Skip to content

Commit 1bd7401

Browse files
committed
[optimize] simplify i18n imports & Component props
[optimize] update Upstream packages
1 parent dcd55f1 commit 1bd7401

File tree

12 files changed

+1322
-1404
lines changed

12 files changed

+1322
-1404
lines changed

.github/workflows/replace-repository-name.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ SourceName=$2
55
TargetOwner=$3
66
TargetName=$4
77

8-
sed -i "s/$SourceOwner\/$SourceName/$TargetOwner\/$TargetName/ig" $(grep -i $SourceOwner/$SourceName -rl .)
9-
sed -i "s/$SourceOwner/$TargetOwner/ig" $(grep -i $SourceOwner -rl .)
10-
sed -i "s/$SourceName/$TargetName/ig" $(grep -i $SourceName -rl .)
8+
sed -i "s/$SourceOwner\/$SourceName/$TargetOwner\/$TargetName/ig" \
9+
$(grep -i $SourceOwner/$SourceName -rl . --exclude-dir=.git --exclude-dir=node_modules)
10+
sed -i "s/$SourceOwner/$TargetOwner/ig" \
11+
$(grep -i $SourceOwner -rl . --exclude-dir=.git --exclude-dir=node_modules)
12+
sed -i "s/$SourceName/$TargetName/ig" \
13+
$(grep -i $SourceName -rl . --exclude-dir=.git --exclude-dir=node_modules)

components/Git/Card.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import { text2color } from 'idea-react';
22
import { GitRepository } from 'mobx-github';
33
import { observer } from 'mobx-react';
44
import { FC } from 'react';
5-
import { Badge, Button, Card, Col, Row } from 'react-bootstrap';
5+
import { Badge, Button, Card, CardProps, Col, Row } from 'react-bootstrap';
66

7-
import { i18n } from '../../models/Translation';
7+
import { t } from '../../models/Translation';
88
import { GitLogo } from './Logo';
99

1010
export interface GitCardProps
11-
extends Pick<GitRepository, 'full_name' | 'html_url' | 'languages'>,
11+
extends Omit<CardProps, 'id'>,
12+
Pick<GitRepository, 'full_name' | 'html_url' | 'languages'>,
1213
Partial<Pick<GitRepository, 'topics' | 'description' | 'homepage'>> {
1314
className?: string;
1415
}
@@ -22,8 +23,9 @@ export const GitCard: FC<GitCardProps> = observer(
2223
topics = [],
2324
description,
2425
homepage,
26+
...props
2527
}) => (
26-
<Card className={className}>
28+
<Card className={className} {...props}>
2729
<Card.Body className="d-flex flex-column gap-3">
2830
<Card.Title as="h3" className="h5">
2931
<a target="_blank" href={html_url} rel="noreferrer">
@@ -57,7 +59,7 @@ export const GitCard: FC<GitCardProps> = observer(
5759
<Card.Footer className="d-flex justify-content-between align-items-center">
5860
{homepage && (
5961
<Button variant="success" target="_blank" href={homepage}>
60-
{i18n.t('home_page')}
62+
{t('home_page')}
6163
</Button>
6264
)}
6365
</Card.Footer>

components/Git/Logo.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { observable } from 'mobx';
22
import { observer } from 'mobx-react';
3-
import { PureComponent } from 'react';
4-
import { Image } from 'react-bootstrap';
3+
import { Component } from 'react';
4+
import { Image, ImageProps } from 'react-bootstrap';
55

6-
export interface GitLogoProps {
6+
export interface GitLogoProps extends ImageProps {
77
name: string;
88
}
99

1010
@observer
11-
export class GitLogo extends PureComponent<GitLogoProps> {
11+
export class GitLogo extends Component<GitLogoProps> {
1212
@observable
1313
accessor path = '';
1414

@@ -41,8 +41,8 @@ export class GitLogo extends PureComponent<GitLogoProps> {
4141

4242
render() {
4343
const { path } = this;
44-
const { name } = this.props;
44+
const { name, ...props } = this.props;
4545

46-
return path && <Image fluid src={path} alt={name} />;
46+
return path && <Image fluid {...props} src={path} alt={name} />;
4747
}
4848
}

components/MainNavigator.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ import dynamic from 'next/dynamic';
33
import { FC } from 'react';
44
import { Container, Nav, Navbar } from 'react-bootstrap';
55

6-
import { i18n } from '../models/Translation';
6+
import { t } from '../models/Translation';
77

8-
const { t } = i18n,
9-
LanguageMenu = dynamic(import('./LanguageMenu'), { ssr: false });
8+
const LanguageMenu = dynamic(import('./LanguageMenu'), { ssr: false });
109

1110
const Name = process.env.NEXT_PUBLIC_SITE_NAME || '';
1211

models/Translation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ export const i18n = new TranslationModel({
88
'en-US': () => import('../translation/en-US'),
99
});
1010

11-
export const LanguageName: Record<typeof i18n['currentLanguage'], string> = {
11+
export const { t } = i18n;
12+
13+
export const LanguageName: Record<(typeof i18n)['currentLanguage'], string> = {
1214
'zh-CN': '简体中文',
1315
'zh-TW': '繁體中文',
1416
'en-US': 'English',

package.json

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,77 @@
77
"node": ">=20"
88
},
99
"dependencies": {
10-
"@editorjs/code": "^2.9.2",
11-
"@editorjs/editorjs": "^2.30.6",
10+
"@editorjs/code": "^2.9.3",
11+
"@editorjs/editorjs": "^2.30.7",
1212
"@editorjs/header": "^2.8.8",
13-
"@editorjs/image": "^2.9.3",
13+
"@editorjs/image": "^2.10.1",
1414
"@editorjs/link": "^2.6.2",
15-
"@editorjs/list": "^1.10.0",
15+
"@editorjs/list": "^2.0.2",
1616
"@editorjs/paragraph": "^2.11.6",
17-
"@editorjs/quote": "~2.7.2",
17+
"@editorjs/quote": "~2.7.4",
1818
"@mdx-js/loader": "^3.1.0",
1919
"@mdx-js/react": "^3.1.0",
20-
"@next/mdx": "^15.0.1",
21-
"@sentry/nextjs": "^8.35.0",
20+
"@next/mdx": "^15.0.3",
21+
"@sentry/nextjs": "^8.41.0",
2222
"copy-webpack-plugin": "^12.0.2",
2323
"editorjs-html": "^3.4.3",
2424
"idea-react": "^2.0.0-rc.8",
25-
"koajax": "^3.0.2",
26-
"less": "^4.2.0",
25+
"koajax": "^3.0.3",
26+
"less": "^4.2.1",
2727
"less-loader": "^12.2.0",
2828
"lodash": "^4.17.21",
2929
"mobx": "^6.13.5",
30-
"mobx-github": "^0.3.4",
30+
"mobx-github": "^0.3.5",
3131
"mobx-i18n": "^0.6.0",
3232
"mobx-react": "^9.1.1",
33-
"mobx-restful": "^1.0.1",
33+
"mobx-restful": "^2.0.0",
3434
"mobx-restful-table": "^2.0.0",
35-
"next": "^15.0.1",
35+
"next": "^15.0.3",
3636
"next-pwa": "~5.6.0",
37-
"next-ssr-middleware": "^0.8.8",
37+
"next-ssr-middleware": "^0.8.9",
3838
"next-with-less": "^3.0.1",
3939
"prismjs": "^1.29.0",
4040
"react": "^18.3.1",
41-
"react-bootstrap": "^2.10.5",
41+
"react-bootstrap": "^2.10.6",
4242
"react-bootstrap-editor": "^2.0.4",
4343
"react-dom": "^18.3.1",
4444
"react-editor-js": "^2.1.0",
4545
"remark-frontmatter": "^5.0.0",
4646
"remark-gfm": "^4.0.0",
4747
"remark-mdx-frontmatter": "^5.0.0",
48-
"undici": "^6.20.1",
49-
"web-utility": "^4.4.1",
50-
"webpack": "^5.95.0"
48+
"undici": "^7.0.0",
49+
"web-utility": "^4.4.2",
50+
"webpack": "^5.96.1"
5151
},
5252
"devDependencies": {
5353
"@babel/plugin-proposal-decorators": "^7.25.9",
5454
"@babel/plugin-transform-typescript": "^7.25.9",
5555
"@babel/preset-react": "^7.25.9",
56-
"@eslint/compat": "^1.2.1",
57-
"@eslint/eslintrc": "^3.1.0",
58-
"@eslint/js": "^9.13.0",
59-
"@softonus/prettier-plugin-duplicate-remover": "^1.0.1",
56+
"@eslint/compat": "^1.2.3",
57+
"@eslint/eslintrc": "^3.2.0",
58+
"@eslint/js": "^9.15.0",
59+
"@softonus/prettier-plugin-duplicate-remover": "^1.1.2",
6060
"@types/eslint-config-prettier": "^6.11.3",
6161
"@types/eslint__eslintrc": "^2.1.2",
6262
"@types/eslint__js": "^8.42.3",
63-
"@types/lodash": "^4.17.12",
63+
"@types/lodash": "^4.17.13",
6464
"@types/next-pwa": "^5.6.9",
65-
"@types/node": "^20.17.1",
65+
"@types/node": "^20.17.8",
6666
"@types/react": "^18.3.12",
67-
"eslint": "^9.13.0",
68-
"eslint-config-next": "^15.0.1",
67+
"eslint": "^9.15.0",
68+
"eslint-config-next": "^15.0.3",
6969
"eslint-config-prettier": "^9.1.0",
7070
"eslint-plugin-react": "^7.37.2",
7171
"eslint-plugin-simple-import-sort": "^12.1.1",
72-
"globals": "^15.11.0",
73-
"husky": "^9.1.6",
72+
"globals": "^15.12.0",
73+
"husky": "^9.1.7",
7474
"lint-staged": "^15.2.10",
75-
"prettier": "^3.3.3",
75+
"prettier": "^3.4.1",
7676
"prettier-plugin-css-order": "^2.1.2",
77-
"typescript": "~5.6.3",
78-
"typescript-eslint": "^8.11.0"
77+
"typescript": "~5.7.2",
78+
"typescript-eslint": "^8.16.0"
7979
},
8080
"resolutions": {
81-
"native-file-system-adapter": "npm:@tech_query/native-file-system-adapter@^3.0.1",
8281
"next": "$next"
8382
},
8483
"prettier": {

pages/_app.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,19 @@ import { Image } from 'react-bootstrap';
1111
import { MainNavigator } from '../components/MainNavigator';
1212
import { MDXLayout } from '../components/MDXLayout';
1313
import { isServer } from '../models/Base';
14-
import { i18n } from '../models/Translation';
14+
import { t } from '../models/Translation';
1515

1616
configure({ enforceActions: 'never' });
1717

1818
enableStaticRendering(isServer());
1919

20-
const { t } = i18n;
21-
2220
globalThis.addEventListener?.('unhandledrejection', ({ reason }) => {
23-
let { message } = reason as HTTPError;
24-
const { statusText, body } = reason.response || {};
21+
const { message, response } = reason as HTTPError;
22+
const { statusText, body } = response || {};
2523

26-
message = body?.message || statusText || message;
24+
const tips = body?.message || statusText || message;
2725

28-
if (message) alert(message);
26+
if (tips) alert(tips);
2927
});
3028

3129
const AppShell: FC<AppProps> = observer(({ Component, pageProps, router }) => (

pages/api/home.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import { i18n } from '../../models/Translation';
2-
3-
const { t } = i18n;
1+
import { t } from '../../models/Translation';
42

53
export const mainNav = () => [
64
{

pages/component.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'prismjs/components/prism-typescript';
1414
import 'prismjs/components/prism-tsx';
1515

1616
import { PageHead } from '../components/PageHead';
17-
import { i18n } from '../models/Translation';
17+
import { i18n, t } from '../models/Translation';
1818
import RichEditData from './api/rich-edit.json';
1919

2020
const HTMLEditor = dynamic(() => import('../components/HTMLEditor'), {
@@ -41,8 +41,6 @@ const Example: FC<PropsWithChildren<{ title: string }>> = ({
4141
export const getServerSideProps = compose(translator(i18n));
4242

4343
const ComponentPage = observer(() => {
44-
const { t } = i18n;
45-
4644
const title = textJoin(t('component'), t('examples'));
4745

4846
return (

pages/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import { Card, Col, Container, Row } from 'react-bootstrap';
44

55
import { GitCard } from '../components/Git/Card';
66
import { PageHead } from '../components/PageHead';
7-
import { i18n } from '../models/Translation';
7+
import { i18n, t } from '../models/Translation';
88
import styles from '../styles/Home.module.less';
99
import { framework, mainNav } from './api/home';
1010

1111
export const getServerSideProps = compose(translator(i18n));
1212

13-
const { t } = i18n;
14-
1513
const HomePage = observer(() => (
1614
<Container as="main" className={styles.main}>
1715
<PageHead />

0 commit comments

Comments
 (0)