-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy path[node_token].tsx
More file actions
56 lines (42 loc) · 1.45 KB
/
[node_token].tsx
File metadata and controls
56 lines (42 loc) · 1.45 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
import { Block, renderBlocks, WikiNode } from 'mobx-lark';
import { GetStaticPaths, GetStaticProps } from 'next';
import { FC } from 'react';
import { Container } from 'react-bootstrap';
import { Minute, Second } from 'web-utility';
import { PageHead } from '../../components/Layout/PageHead';
import { documentStore, wikiStore } from '../../models/Wiki';
import { lark } from '../api/Lark/core';
export const getStaticPaths: GetStaticPaths = async () => {
await lark.getAccessToken();
const nodes = await wikiStore.getAll();
return {
paths: nodes.map(({ node_token }) => ({ params: { node_token } })),
fallback: 'blocking',
};
};
export const getStaticProps: GetStaticProps = async ({ params }) => {
await lark.getAccessToken();
const node = await wikiStore.getOne(params!.node_token as string);
if (node?.obj_type !== 'docx') return { notFound: true };
try {
const blocks = await documentStore.getOneBlocks(
node.obj_token,
token => `/api/Lark/file/${token}/placeholder`,
);
return { props: { node, blocks } };
} catch (error) {
console.error(error);
return { notFound: true, revalidate: Minute / Second };
}
};
interface WikiDocumentPageProps {
node: WikiNode;
blocks: Block<any, any, any>[];
}
const WikiDocumentPage: FC<WikiDocumentPageProps> = ({ node, blocks }) => (
<Container>
<PageHead title={node.title} />
{renderBlocks(blocks)}
</Container>
);
export default WikiDocumentPage;