|
| 1 | +import { Block, renderBlocks, WikiNode } from 'mobx-lark'; |
| 2 | +import { GetStaticPaths, GetStaticProps } from 'next'; |
| 3 | +import { FC } from 'react'; |
| 4 | +import { Container } from 'react-bootstrap'; |
| 5 | + |
| 6 | +import { PageHead } from '../../components/Layout/PageHead'; |
| 7 | +import documentStore from '../../models/Document'; |
| 8 | +import wikiStore from '../../models/Wiki'; |
| 9 | +import { lark } from '../api/Lark/core'; |
| 10 | + |
| 11 | +export const getStaticPaths: GetStaticPaths = async () => { |
| 12 | + await lark.getAccessToken(); |
| 13 | + |
| 14 | + const nodes = await wikiStore.getAll(); |
| 15 | + |
| 16 | + return { |
| 17 | + paths: nodes.map(({ node_token }) => ({ params: { node_token } })), |
| 18 | + fallback: 'blocking', |
| 19 | + }; |
| 20 | +}; |
| 21 | + |
| 22 | +export const getStaticProps: GetStaticProps = async ({ params }) => { |
| 23 | + await lark.getAccessToken(); |
| 24 | + |
| 25 | + const node = await wikiStore.getOne(params!.node_token as string); |
| 26 | + |
| 27 | + if (node?.obj_type !== 'docx') return { notFound: true }; |
| 28 | + |
| 29 | + const blocks = await documentStore.getOneBlocks( |
| 30 | + node.obj_token, |
| 31 | + token => `/api/Lark/file/${token}/placeholder`, |
| 32 | + ); |
| 33 | + |
| 34 | + return { props: { node, blocks } }; |
| 35 | +}; |
| 36 | + |
| 37 | +interface WikiDocumentPageProps { |
| 38 | + node: WikiNode; |
| 39 | + blocks: Block<any, any, any>[]; |
| 40 | +} |
| 41 | + |
| 42 | +const WikiDocumentPage: FC<WikiDocumentPageProps> = ({ node, blocks }) => ( |
| 43 | + <Container> |
| 44 | + <PageHead title={node.title} /> |
| 45 | + |
| 46 | + {renderBlocks(blocks)} |
| 47 | + </Container> |
| 48 | +); |
| 49 | + |
| 50 | +export default WikiDocumentPage; |
0 commit comments