-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path[...slug].tsx
More file actions
155 lines (137 loc) · 4.76 KB
/
[...slug].tsx
File metadata and controls
155 lines (137 loc) · 4.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { marked } from 'marked';
import { GetStaticPaths, GetStaticProps } from 'next';
import Link from 'next/link';
import { ParsedUrlQuery } from 'querystring';
import { FC } from 'react';
import { Badge, Breadcrumb, Button, Container } from 'react-bootstrap';
import { PageHead } from '../../components/Layout/PageHead';
import { WikiNode, wikiStore } from '../../models/Wiki';
interface WikiPageParams extends ParsedUrlQuery {
slug: string[];
}
export const getStaticPaths: GetStaticPaths<WikiPageParams> = async () => {
const nodes = await wikiStore.getAllContent();
const paths = nodes.map(({ path }) => ({
params: { slug: path.split('/') }
}));
return { paths, fallback: 'blocking' };
};
interface WikiPageProps {
node: WikiNode;
markup: string;
}
export const getStaticProps: GetStaticProps<WikiPageProps, WikiPageParams> = async ({ params }) => {
const { slug } = params!;
const nodePath = slug.join('/');
const node = await wikiStore.getWikiContent(nodePath);
const markup = marked(node.content || '') as string;
return {
props: { node, markup },
revalidate: 300 // Revalidate every 5 minutes
};
};
const WikiPage: FC<WikiPageProps> = ({ node, markup }) => (
<Container className="py-4">
<PageHead title={node.title} />
<Breadcrumb className="mb-4">
<Breadcrumb.Item linkAs={Link} linkProps={{ href: '/wiki' }}>
Wiki
</Breadcrumb.Item>
{node.parent_path?.split('/').map((segment, index, array) => {
const breadcrumbPath = array.slice(0, index + 1).join('/');
return (
<Breadcrumb.Item
key={breadcrumbPath}
linkAs={Link}
linkProps={{ href: `/wiki/${breadcrumbPath}` }}
>
{segment}
</Breadcrumb.Item>
);
})}
<Breadcrumb.Item active>
{node.title}
</Breadcrumb.Item>
</Breadcrumb>
<article>
<header className="mb-4">
<h1>{node.title}</h1>
{node.metadata && (
<div className="d-flex flex-wrap align-items-center gap-3 mb-3">
<ul className="list-inline mb-0">
{node.metadata['主题分类'] && (
<li className="list-inline-item">
<Badge bg="primary">{node.metadata['主题分类']}</Badge>
</li>
)}
{node.metadata['发文机构'] && (
<li className="list-inline-item">
<Badge bg="secondary">{node.metadata['发文机构']}</Badge>
</li>
)}
{node.metadata['有效性'] && (
<li className="list-inline-item">
<Badge bg={node.metadata['有效性'] === '现行有效' ? 'success' : 'warning'}>
{node.metadata['有效性']}
</Badge>
</li>
)}
</ul>
</div>
)}
<div className="d-flex justify-content-between align-items-center text-muted small mb-3">
<div>
{node.metadata?.['成文日期'] && (
<span>成文日期: {node.metadata['成文日期']}</span>
)}
{node.metadata?.['发布日期'] && node.metadata['发布日期'] !== node.metadata['成文日期'] && (
<span className="ms-3">发布日期: {node.metadata['发布日期']}</span>
)}
</div>
<div className="d-flex gap-2">
<Button
variant="outline-primary"
size="sm"
href={`https://github.com/fpsig/open-source-policy/blob/main/China/政策/${node.path}`}
target="_blank"
rel="noopener noreferrer"
>
在 GitHub 编辑
</Button>
{node.metadata?.url && (
<Button
variant="outline-secondary"
size="sm"
href={node.metadata.url}
target="_blank"
rel="noopener noreferrer"
>
查看原文
</Button>
)}
</div>
</div>
</header>
<div
dangerouslySetInnerHTML={{ __html: markup }}
className="markdown-body"
/>
</article>
<footer className="mt-5 pt-4 border-top">
<div className="text-center">
<p className="text-muted">
这是一个基于 GitHub 仓库的政策文档页面。
<a
href={`https://github.com/fpsig/open-source-policy/blob/main/China/政策/${node.path}`}
target="_blank"
rel="noopener noreferrer"
className="ms-2"
>
在 GitHub 上查看或编辑此内容
</a>
</p>
</div>
</footer>
</Container>
);
export default WikiPage;