Skip to content

Commit 35e585b

Browse files
CopilotTechQuery
andcommitted
Address code review feedback: add navigation link, acknowledgment, shared components, and BadgeBar
Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
1 parent 0195cb0 commit 35e585b

9 files changed

Lines changed: 88 additions & 100 deletions

File tree

components/Layout/ContentTree.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import Link from 'next/link';
2+
import { FC } from 'react';
3+
import { Badge } from 'react-bootstrap';
4+
5+
import { XContent } from '../../models/Wiki';
6+
7+
interface ContentTreeProps {
8+
nodes: XContent[];
9+
basePath: string;
10+
level?: number;
11+
metaKey?: string;
12+
}
13+
14+
export const ContentTree: FC<ContentTreeProps> = ({ nodes, basePath, level = 0, metaKey = '主题分类' }) => (
15+
<ol className={level === 0 ? 'list-unstyled' : ''}>
16+
{nodes.map(({ path, name, type, meta, children }) => (
17+
<li key={path} className={level > 0 ? 'ms-3' : ''}>
18+
{type !== 'dir' ? (
19+
<Link className="h4 d-flex align-items-center py-1" href={`${basePath}/${path}`}>
20+
{name}
21+
22+
{meta?.[metaKey] && (
23+
<Badge bg="secondary" className="ms-2 small">
24+
{meta[metaKey]}
25+
</Badge>
26+
)}
27+
</Link>
28+
) : (
29+
<details>
30+
<summary className="h4">{name}</summary>
31+
32+
<ContentTree nodes={children || []} basePath={basePath} level={level + 1} metaKey={metaKey} />
33+
</details>
34+
)}
35+
</li>
36+
))}
37+
</ol>
38+
);

components/Navigator/MainNavigator.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ const topNavBarMenu = ({ t }: typeof i18n): MenuItem[] => [
6060
subs: [
6161
{ href: '/wiki', title: t('wiki') },
6262
{ href: '/policy', title: t('policy') },
63+
{ href: '/recipes', title: t('recipes') },
6364
],
6465
},
6566
];

pages/policy/[...slug].tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { marked } from 'marked';
22
import { observer } from 'mobx-react';
3+
import { BadgeBar } from 'mobx-restful-table';
34
import { GetStaticPaths, GetStaticProps } from 'next';
45
import { ParsedUrlQuery } from 'querystring';
56
import { FC, useContext } from 'react';
6-
import { Badge, Breadcrumb, Button, Container } from 'react-bootstrap';
7+
import { Breadcrumb, Button, Container } from 'react-bootstrap';
78
import { decodeBase64 } from 'web-utility';
89

910
import { PageHead } from '../../components/Layout/PageHead';
@@ -68,25 +69,16 @@ const WikiPage: FC<XContent> = observer(({ name, path, parent_path, content, met
6869

6970
{meta && (
7071
<div className="d-flex flex-wrap align-items-center gap-3 mb-3">
71-
<ul className="mb-0">
72-
{meta['主题分类'] && (
73-
<li>
74-
<Badge bg="primary">{meta['主题分类']}</Badge>
75-
</li>
76-
)}
77-
{meta['发文机构'] && (
78-
<li>
79-
<Badge bg="secondary">{meta['发文机构']}</Badge>
80-
</li>
81-
)}
82-
{meta['有效性'] && (
83-
<li>
84-
<Badge bg={meta['有效性'] === '现行有效' ? 'success' : 'warning'}>
85-
{meta['有效性']}
86-
</Badge>
87-
</li>
88-
)}
89-
</ul>
72+
<BadgeBar
73+
list={[
74+
meta['主题分类'] && { text: meta['主题分类'], color: 'primary' },
75+
meta['发文机构'] && { text: meta['发文机构'], color: 'secondary' },
76+
meta['有效性'] && {
77+
text: meta['有效性'],
78+
color: meta['有效性'] === '现行有效' ? 'success' : 'warning'
79+
}
80+
].filter(Boolean) as Array<{ text: string; color?: string }>}
81+
/>
9082
</div>
9183
)}
9284

pages/policy/index.tsx

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { observer } from 'mobx-react';
22
import { GetStaticProps } from 'next';
3-
import Link from 'next/link';
43
import React, { FC, useContext } from 'react';
5-
import { Badge, Button, Card, Container } from 'react-bootstrap';
4+
import { Button, Card, Container } from 'react-bootstrap';
65
import { treeFrom } from 'web-utility';
76

7+
import { ContentTree } from '../../components/Layout/ContentTree';
88
import { PageHead } from '../../components/Layout/PageHead';
99
import { I18nContext } from '../../models/Translation';
1010
import { policyContentStore, XContent } from '../../models/Wiki';
@@ -25,32 +25,6 @@ export const getStaticProps: GetStaticProps<{ nodes: XContent[] }> = async () =>
2525
};
2626
};
2727

28-
const renderTree = (nodes: XContent[], level = 0) => (
29-
<ol className={level === 0 ? 'list-unstyled' : ''}>
30-
{nodes.map(({ path, name, type, meta, children }) => (
31-
<li key={path} className={level > 0 ? 'ms-3' : ''}>
32-
{type !== 'dir' ? (
33-
<Link className="h4 d-flex align-items-center py-1" href={`/policy/${path}`}>
34-
{name}
35-
36-
{meta?.['主题分类'] && (
37-
<Badge bg="secondary" className="ms-2 small">
38-
{meta['主题分类']}
39-
</Badge>
40-
)}
41-
</Link>
42-
) : (
43-
<details>
44-
<summary className="h4">{name}</summary>
45-
46-
{renderTree(children || [], level + 1)}
47-
</details>
48-
)}
49-
</li>
50-
))}
51-
</ol>
52-
);
53-
5428
const WikiIndexPage: FC<{ nodes: XContent[] }> = observer(({ nodes }) => {
5529
const { t } = useContext(I18nContext);
5630

@@ -73,7 +47,11 @@ const WikiIndexPage: FC<{ nodes: XContent[] }> = observer(({ nodes }) => {
7347
</hgroup>
7448

7549
{nodes[0] ? (
76-
renderTree(treeFrom(nodes, 'path', 'parent_path', 'children'))
50+
<ContentTree
51+
nodes={treeFrom(nodes, 'path', 'parent_path', 'children')}
52+
basePath="/policy"
53+
metaKey="主题分类"
54+
/>
7755
) : (
7856
<Card>
7957
<Card.Body className="text-muted text-center">

pages/recipes/[...slug].tsx

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { marked } from 'marked';
22
import { observer } from 'mobx-react';
3+
import { BadgeBar } from 'mobx-restful-table';
34
import { GetStaticPaths, GetStaticProps } from 'next';
45
import { ParsedUrlQuery } from 'querystring';
56
import { FC, useContext } from 'react';
6-
import { Badge, Breadcrumb, Button, Container } from 'react-bootstrap';
7+
import { Breadcrumb, Button, Container } from 'react-bootstrap';
78
import { decodeBase64 } from 'web-utility';
89

910
import { PageHead } from '../../components/Layout/PageHead';
@@ -68,23 +69,13 @@ const RecipePage: FC<XContent> = observer(({ name, path, parent_path, content, m
6869

6970
{meta && (
7071
<div className="d-flex flex-wrap align-items-center gap-3 mb-3">
71-
<ul className="mb-0">
72-
{meta['category'] && (
73-
<li>
74-
<Badge bg="primary">{meta['category']}</Badge>
75-
</li>
76-
)}
77-
{meta['difficulty'] && (
78-
<li>
79-
<Badge bg="secondary">{meta['difficulty']}</Badge>
80-
</li>
81-
)}
82-
{meta['time'] && (
83-
<li>
84-
<Badge bg="success">{meta['time']}</Badge>
85-
</li>
86-
)}
87-
</ul>
72+
<BadgeBar
73+
list={[
74+
meta['category'] && { text: meta['category'], color: 'primary' },
75+
meta['difficulty'] && { text: meta['difficulty'], color: 'secondary' },
76+
meta['time'] && { text: meta['time'], color: 'success' }
77+
].filter(Boolean) as Array<{ text: string; color?: string }>}
78+
/>
8879
</div>
8980
)}
9081

@@ -133,7 +124,7 @@ const RecipePage: FC<XContent> = observer(({ name, path, parent_path, content, m
133124
<footer className="mt-5 pt-4 border-top">
134125
<div className="text-center">
135126
<p className="text-muted">
136-
{t('github_recipe_description')}
127+
{t('github_document_description')}
137128
<a
138129
href={`https://github.com/Gar-b-age/CookLikeHOC/blob/main/${path}`}
139130
target="_blank"

pages/recipes/index.tsx

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { observer } from 'mobx-react';
22
import { GetStaticProps } from 'next';
3-
import Link from 'next/link';
43
import React, { FC, useContext } from 'react';
5-
import { Badge, Button, Card, Container } from 'react-bootstrap';
4+
import { Button, Card, Container } from 'react-bootstrap';
65
import { treeFrom } from 'web-utility';
76

7+
import { ContentTree } from '../../components/Layout/ContentTree';
88
import { PageHead } from '../../components/Layout/PageHead';
99
import { I18nContext } from '../../models/Translation';
1010
import { recipeContentStore, XContent } from '../../models/Wiki';
@@ -25,32 +25,6 @@ export const getStaticProps: GetStaticProps<{ nodes: XContent[] }> = async () =>
2525
};
2626
};
2727

28-
const renderTree = (nodes: XContent[], level = 0) => (
29-
<ol className={level === 0 ? 'list-unstyled' : ''}>
30-
{nodes.map(({ path, name, type, meta, children }) => (
31-
<li key={path} className={level > 0 ? 'ms-3' : ''}>
32-
{type !== 'dir' ? (
33-
<Link className="h4 d-flex align-items-center py-1" href={`/recipes/${path}`}>
34-
{name}
35-
36-
{meta?.['category'] && (
37-
<Badge bg="secondary" className="ms-2 small">
38-
{meta['category']}
39-
</Badge>
40-
)}
41-
</Link>
42-
) : (
43-
<details>
44-
<summary className="h4">{name}</summary>
45-
46-
{renderTree(children || [], level + 1)}
47-
</details>
48-
)}
49-
</li>
50-
))}
51-
</ol>
52-
);
53-
5428
const RecipeIndexPage: FC<{ nodes: XContent[] }> = observer(({ nodes }) => {
5529
const { t } = useContext(I18nContext);
5630

@@ -72,8 +46,25 @@ const RecipeIndexPage: FC<{ nodes: XContent[] }> = observer(({ nodes }) => {
7246
</Button>
7347
</hgroup>
7448

49+
<div className="alert alert-info mb-4" role="alert">
50+
<p className="mb-1">
51+
<strong>感谢老乡鸡餐饮公司及开源菜谱仓库原作者</strong>
52+
</p>
53+
<p className="mb-0">
54+
本菜谱内容来自{' '}
55+
<a href="https://github.com/Gar-b-age/CookLikeHOC" target="_blank" rel="noopener noreferrer">
56+
CookLikeHOC 开源菜谱项目
57+
</a>
58+
,感谢原作者们的贡献与分享。
59+
</p>
60+
</div>
61+
7562
{nodes[0] ? (
76-
renderTree(treeFrom(nodes, 'path', 'parent_path', 'children'))
63+
<ContentTree
64+
nodes={treeFrom(nodes, 'path', 'parent_path', 'children')}
65+
basePath="/recipes"
66+
metaKey="category"
67+
/>
7768
) : (
7869
<Card>
7970
<Card.Body className="text-muted text-center">

translation/en-US.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ export default {
106106
recipes: 'Recipes',
107107
servings: 'Servings',
108108
prep_time: 'Prep Time',
109-
github_recipe_description: 'This is a recipe page based on a GitHub repository.',
110109

111110
// China NGO Map
112111
NGO: 'NGO',

translation/zh-CN.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export default {
104104
recipes: '菜谱',
105105
servings: '份数',
106106
prep_time: '准备时间',
107-
github_recipe_description: '这是一个基于 GitHub 仓库的菜谱页面。',
108107

109108
// China Public Interest Map
110109
NGO: '公益',

translation/zh-TW.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ export default {
104104
recipes: '菜譜',
105105
servings: '份數',
106106
prep_time: '準備時間',
107-
github_recipe_description: '這是一個基於 GitHub 存儲庫的菜譜頁面。',
108107

109108
// China Public Interest Map
110109
NGO: '公益',

0 commit comments

Comments
 (0)