Skip to content

Commit 566646d

Browse files
committed
[optimize] move Wiki pages to Policy routes
[optimize] translate Policy detail page
1 parent 29eb9c1 commit 566646d

File tree

9 files changed

+184
-151
lines changed

9 files changed

+184
-151
lines changed

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ After making ANY changes, ALWAYS validate by running through these scenarios:
4444
2. **Navigate to homepage**: Visit http://localhost:3000 and verify page loads with navigation menu
4545
3. **Test core pages**:
4646
- License filter: http://localhost:3000/license-filter (interactive license selection tool)
47-
- Wiki pages: http://localhost:3000/wiki (policy documents from GitHub)
47+
- Wiki pages: http://localhost:3000/policy (policy documents from GitHub)
4848
- Volunteer page: http://localhost:3000/volunteer (contributor showcase)
4949
- Projects: http://localhost:3000/project (GitHub repository listings)
5050
4. **Test API endpoints**: Verify GitHub API integrations work

components/Navigator/MainNavigator.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const topNavBarMenu = ({ t }: typeof i18n): MenuItem[] => [
2727
name: t('hackathon'),
2828
},
2929
{ href: '/license-filter', name: t('license_filter') },
30-
{ href: '/wiki', name: t('wiki') },
30+
{ href: '/policy', name: t('policy') },
3131
];
3232

3333
export interface MainNavigatorProps {

pages/_app.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export default class CustomApp extends App<I18nProps> {
5555
<MainNavigator />
5656

5757
<div className="mt-5 pt-2">
58-
{asPath.startsWith('/article/') || asPath.startsWith('/wiki/') ? (
58+
{asPath.startsWith('/article/') || asPath.startsWith('/policy/') ? (
5959
<PageContent>
6060
<Component {...pageProps} />
6161
</PageContent>

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

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
import { marked } from 'marked';
2+
import { observer } from 'mobx-react';
3+
import { GetStaticPaths, GetStaticProps } from 'next';
4+
import { ParsedUrlQuery } from 'querystring';
5+
import { FC, useContext } from 'react';
6+
import { Badge, Breadcrumb, Button, Container } from 'react-bootstrap';
7+
import { decodeBase64 } from 'web-utility';
8+
9+
import { PageHead } from '../../components/Layout/PageHead';
10+
import { I18nContext } from '../../models/Translation';
11+
import { policyContentStore, XContent } from '../../models/Wiki';
12+
import { splitFrontMatter } from '../api/core';
13+
14+
interface WikiPageParams extends ParsedUrlQuery {
15+
slug: string[];
16+
}
17+
18+
export const getStaticPaths: GetStaticPaths<WikiPageParams> = async () => {
19+
const nodes = await policyContentStore.getAll();
20+
21+
const paths = nodes
22+
.filter(({ type }) => type === 'file')
23+
.map(({ path }) => ({ params: { slug: path.split('/') } }));
24+
25+
return { paths, fallback: 'blocking' };
26+
};
27+
28+
export const getStaticProps: GetStaticProps<XContent, WikiPageParams> = async ({ params }) => {
29+
const { slug } = params!;
30+
31+
const node = await policyContentStore.getOne(slug.join('/'));
32+
33+
const { meta, markdown } = splitFrontMatter(decodeBase64(node.content!));
34+
35+
const markup = marked(markdown) as string;
36+
37+
return {
38+
props: JSON.parse(JSON.stringify({ ...node, content: markup, meta })),
39+
revalidate: 300, // Revalidate every 5 minutes
40+
};
41+
};
42+
43+
const WikiPage: FC<XContent> = observer(({ name, path, parent_path, content, meta }) => {
44+
const { t } = useContext(I18nContext);
45+
46+
return (
47+
<Container className="py-4">
48+
<PageHead title={name} />
49+
50+
<Breadcrumb className="mb-4">
51+
<Breadcrumb.Item href="/policy">{t('policy')}</Breadcrumb.Item>
52+
53+
{parent_path?.split('/').map((segment, index, array) => {
54+
const breadcrumbPath = array.slice(0, index + 1).join('/');
55+
56+
return (
57+
<Breadcrumb.Item key={breadcrumbPath} href={`/policy/${breadcrumbPath}`}>
58+
{segment}
59+
</Breadcrumb.Item>
60+
);
61+
})}
62+
<Breadcrumb.Item active>{name}</Breadcrumb.Item>
63+
</Breadcrumb>
64+
65+
<article>
66+
<header className="mb-4">
67+
<h1>{name}</h1>
68+
69+
{meta && (
70+
<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>
90+
</div>
91+
)}
92+
93+
<div className="d-flex justify-content-between align-items-center text-muted small mb-3">
94+
<div>
95+
{meta?.['成文日期'] && (
96+
<span>
97+
{t('creation_date')}: {meta['成文日期']}
98+
</span>
99+
)}
100+
{meta?.['发布日期'] && meta['发布日期'] !== meta['成文日期'] && (
101+
<span className="ms-3">
102+
{t('publication_date')}: {meta['发布日期']}
103+
</span>
104+
)}
105+
</div>
106+
107+
<div className="d-flex gap-2">
108+
<Button
109+
variant="outline-primary"
110+
size="sm"
111+
href={`https://github.com/fpsig/open-source-policy/blob/main/China/政策/${path}`}
112+
target="_blank"
113+
rel="noopener noreferrer"
114+
>
115+
{t('edit_on_github')}
116+
</Button>
117+
{meta?.url && (
118+
<Button
119+
variant="outline-secondary"
120+
size="sm"
121+
href={meta.url}
122+
target="_blank"
123+
rel="noopener noreferrer"
124+
>
125+
{t('view_original')}
126+
</Button>
127+
)}
128+
</div>
129+
</div>
130+
</header>
131+
132+
<div dangerouslySetInnerHTML={{ __html: content || '' }} className="markdown-body" />
133+
</article>
134+
135+
<footer className="mt-5 pt-4 border-top">
136+
<div className="text-center">
137+
<p className="text-muted">
138+
{t('github_document_description')}
139+
<a
140+
href={`https://github.com/fpsig/open-source-policy/blob/main/China/政策/${path}`}
141+
target="_blank"
142+
rel="noopener noreferrer"
143+
className="ms-2"
144+
>
145+
{t('view_or_edit_on_github')}
146+
</a>
147+
</p>
148+
</div>
149+
</footer>
150+
</Container>
151+
);
152+
});
153+
154+
export default WikiPage;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const renderTree = (nodes: XContent[], level = 0) => (
3030
{nodes.map(({ path, name, type, meta, children }) => (
3131
<li key={path} className={level > 0 ? 'ms-3' : ''}>
3232
{type !== 'dir' ? (
33-
<Link className="h4 d-flex align-items-center py-1" href={`/wiki/${path}`}>
33+
<Link className="h4 d-flex align-items-center py-1" href={`/policy/${path}`}>
3434
{name}
3535

3636
{meta?.['主题分类'] && (
@@ -56,11 +56,11 @@ const WikiIndexPage: FC<{ nodes: XContent[] }> = observer(({ nodes }) => {
5656

5757
return (
5858
<Container className="py-4">
59-
<PageHead title={`${t('wiki')} - ${t('knowledge_base')}`} />
59+
<PageHead title={`${t('policy')} - ${t('knowledge_base')}`} />
6060

6161
<hgroup className="d-flex justify-content-between align-items-center mb-4">
6262
<h1>
63-
{t('wiki')} ({nodes.length})
63+
{t('policy')} ({nodes.length})
6464
</h1>
6565
<Button
6666
href="https://github.com/fpsig/open-source-policy"

pages/wiki/[...slug].tsx

Lines changed: 0 additions & 142 deletions
This file was deleted.

translation/en-US.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,17 @@ export default {
7878
range_file: 'file',
7979
range_module: 'module',
8080
last_step: 'back',
81-
81+
8282
// Wiki
8383
knowledge_base: 'Knowledge Base',
8484
contribute_content: 'Contribute Content',
8585
no_docs_available: 'No documents available in the knowledge base.',
8686
docs_auto_load_from_github: 'Documents will be automatically loaded from GitHub repository.',
87+
policy: 'Policy',
88+
creation_date: 'Creation Date',
89+
publication_date: 'Publication Date',
90+
edit_on_github: 'Edit on GitHub',
91+
view_original: 'View Original',
92+
github_document_description: 'This is a document page based on a GitHub repository.',
93+
view_or_edit_on_github: 'View or edit this content on GitHub',
8794
};

translation/zh-CN.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,17 @@ export default {
7777
range_file: '文件',
7878
range_module: '模块',
7979
last_step: '上一步',
80-
80+
8181
// Wiki
8282
knowledge_base: '知识库',
8383
contribute_content: '贡献内容',
8484
no_docs_available: '知识库暂无文档。',
8585
docs_auto_load_from_github: '文档将从 GitHub 仓库中自动加载。',
86+
policy: '政策',
87+
creation_date: '成文日期',
88+
publication_date: '发布日期',
89+
edit_on_github: '在 GitHub 编辑',
90+
view_original: '查看原文',
91+
github_document_description: '这是一个基于 GitHub 仓库的文档页面。',
92+
view_or_edit_on_github: '在 GitHub 上查看或编辑此内容',
8693
};

0 commit comments

Comments
 (0)