Skip to content

Commit 22f018b

Browse files
CopilotTechQuery
andcommitted
Changes before error encountered
Co-authored-by: TechQuery <19969570+TechQuery@users.noreply.github.com>
1 parent 556e842 commit 22f018b

8 files changed

Lines changed: 46 additions & 36 deletions

File tree

models/Wiki.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ export interface WikiNode {
1616
html_url?: string;
1717
git_url?: string;
1818
download_url?: string;
19-
// Frontmatter fields
20-
metadata?: Record<string, string>;
2119
content?: string;
20+
metadata?: Record<string, string>;
2221
}
2322

24-
export class WikiModel {
25-
// For now, only use filesystem reading for simplicity
23+
class WikiModel {
24+
// TODO: Use ContentModel from mobx-github once authentication is configured
25+
// private contentModel = new ContentModel('fpsig', 'open-source-policy');
2626

27-
// Method for build-time static generation
28-
async getAllContentStatic(): Promise<WikiNode[]> {
27+
async getAllContent(): Promise<WikiNode[]> {
2928
const items: WikiNode[] = [];
3029
const policyDir = path.join(process.cwd(), 'public/wiki/policy/China/政策');
3130

@@ -73,22 +72,12 @@ export class WikiModel {
7372
return items;
7473
}
7574

76-
// Method for all environments - use static reading
77-
async getAllContent(): Promise<WikiNode[]> {
78-
return this.getAllContentStatic();
79-
}
80-
8175
async getContentTree(): Promise<WikiNode[]> {
8276
const allContent = await this.getAllContent();
8377
return treeFrom(allContent, 'path', 'parent_path', 'children');
8478
}
8579

86-
async getOne(path: string): Promise<WikiNode> {
87-
return this.getOneStatic(path);
88-
}
89-
90-
// Static method for build-time reading
91-
async getOneStatic(pathParam: string): Promise<WikiNode> {
80+
async getWikiContent(pathParam: string): Promise<WikiNode> {
9281
const fullPath = pathParam.endsWith('.md') ? pathParam : `${pathParam}.md`;
9382
const filePath = path.join(process.cwd(), 'public/wiki/policy/China/政策', fullPath);
9483

pages/_document.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export default class CustomDocument extends Document<CustomDocumentProps> {
4040
rel="stylesheet"
4141
href="https://unpkg.com/bootstrap-icons@1.13.1/font/bootstrap-icons.css"
4242
/>
43+
<link
44+
rel="stylesheet"
45+
href="https://unpkg.com/github-markdown-css@5.8.1/github-markdown.css"
46+
/>
4347
</Head>
4448

4549
<body>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const getStaticProps: GetStaticProps<WikiPageProps, WikiPageParams> = asy
3030
const { slug } = params!;
3131
const nodePath = slug.join('/');
3232

33-
const node = await wikiStore.getOne(nodePath);
33+
const node = await wikiStore.getWikiContent(nodePath);
3434
const markup = marked(node.content || '') as string;
3535

3636
return {
@@ -47,7 +47,7 @@ const WikiPage: FC<WikiPageProps> = ({ node, markup }) => (
4747
<Breadcrumb.Item linkAs={Link} linkProps={{ href: '/wiki' }}>
4848
Wiki
4949
</Breadcrumb.Item>
50-
{node.parent_path && node.parent_path.split('/').map((segment, index, array) => {
50+
{node.parent_path?.split('/').map((segment, index, array) => {
5151
const breadcrumbPath = array.slice(0, index + 1).join('/');
5252

5353
return (

pages/wiki/index.tsx

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { observer } from 'mobx-react';
22
import { GetStaticProps } from 'next';
33
import React, { FC, useContext } from 'react';
4-
import { Container } from 'react-bootstrap';
4+
import { Badge, Card, Container } from 'react-bootstrap';
55
import { treeFrom } from 'web-utility';
66

77
import { PageHead } from '../../components/Layout/PageHead';
@@ -17,8 +17,8 @@ export const getStaticProps: GetStaticProps = async () => {
1717
};
1818
};
1919

20-
const renderTree = (nodes: WikiNode[], level = 0): React.ReactElement => (
21-
<ul className={level === 0 ? 'list-unstyled' : ''}>
20+
const renderTree = (nodes: WikiNode[], level = 0) => (
21+
<ol className={level === 0 ? 'list-unstyled' : ''}>
2222
{nodes.map((node) => (
2323
<li key={node.path} className={level > 0 ? 'ms-3' : ''}>
2424
<div className="d-flex align-items-center py-1">
@@ -29,41 +29,43 @@ const renderTree = (nodes: WikiNode[], level = 0): React.ReactElement => (
2929
{node.title}
3030
</a>
3131
{node.metadata?.['主题分类'] && (
32-
<span className="badge bg-secondary ms-2 small">
32+
<Badge bg="secondary" className="ms-2 small">
3333
{node.metadata['主题分类']}
34-
</span>
34+
</Badge>
3535
)}
3636
</div>
37-
{node.children && node.children.length > 0 && renderTree(node.children, level + 1)}
37+
{node.children?.length && node.children.length > 0 && renderTree(node.children, level + 1)}
3838
</li>
3939
))}
40-
</ul>
40+
</ol>
4141
);
4242

4343
const WikiIndexPage: FC<{ nodes: WikiNode[] }> = observer(({ nodes }) => {
4444
const { t } = useContext(I18nContext);
4545

4646
return (
4747
<Container className="py-4">
48-
<PageHead title={`${t('wiki')} - 政策文档`} />
48+
<PageHead title={`${t('wiki')} - ${t('knowledge_base')}`} />
4949

5050
<div className="d-flex justify-content-between align-items-center mb-4">
51-
<h1>政策 Wiki ({nodes.length})</h1>
51+
<h1>{t('wiki')} ({nodes.length})</h1>
5252
<a
5353
href="https://github.com/fpsig/open-source-policy"
5454
target="_blank"
5555
rel="noopener noreferrer"
5656
className="btn btn-outline-primary"
5757
>
58-
贡献内容
58+
{t('contribute_content')}
5959
</a>
6060
</div>
6161

6262
{nodes.length === 0 ? (
63-
<div className="text-muted">
64-
<p>暂无政策文档。</p>
65-
<p>政策文档将从 GitHub 仓库中自动加载。</p>
66-
</div>
63+
<Card>
64+
<Card.Body className="text-muted text-center">
65+
<p>{t('no_docs_available')}</p>
66+
<p>{t('docs_auto_load_from_github')}</p>
67+
</Card.Body>
68+
</Card>
6769
) : (
6870
renderTree(
6971
treeFrom(nodes, 'path', 'parent_path', 'children'),

styles/globals.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,3 @@ article {
3131
max-width: 100%;
3232
}
3333
}
34-
35-
/* Import GitHub Markdown CSS */
36-
@import 'github-markdown-css/github-markdown.css';

translation/en-US.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,10 @@ export default {
7878
range_file: 'file',
7979
range_module: 'module',
8080
last_step: 'back',
81+
82+
// Wiki
83+
knowledge_base: 'Knowledge Base',
84+
contribute_content: 'Contribute Content',
85+
no_docs_available: 'No documents available in the knowledge base.',
86+
docs_auto_load_from_github: 'Documents will be automatically loaded from GitHub repository.',
8187
};

translation/zh-CN.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,10 @@ export default {
7777
range_file: '文件',
7878
range_module: '模块',
7979
last_step: '上一步',
80+
81+
// Wiki
82+
knowledge_base: '知识库',
83+
contribute_content: '贡献内容',
84+
no_docs_available: '知识库暂无文档。',
85+
docs_auto_load_from_github: '文档将从 GitHub 仓库中自动加载。',
8086
};

translation/zh-TW.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,10 @@ export default {
7777
range_file: '檔案',
7878
range_module: '模組',
7979
last_step: '上一步',
80+
81+
// Wiki
82+
knowledge_base: '知識庫',
83+
contribute_content: '貢獻內容',
84+
no_docs_available: '知識庫暫無文檔。',
85+
docs_auto_load_from_github: '文檔將從 GitHub 存儲庫中自動加載。',
8086
};

0 commit comments

Comments
 (0)