Skip to content

Commit ab6f385

Browse files
committed
[add] Static example pages for Lark Wiki documents
1 parent 9208113 commit ab6f385

File tree

8 files changed

+121
-8
lines changed

8 files changed

+121
-8
lines changed

.env

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ NEXT_PUBLIC_SENTRY_DSN =
66
SENTRY_ORG =
77
SENTRY_PROJECT =
88

9-
NEXT_PUBLIC_LARK_API_HOST = https://open.larksuite.com/open-apis/
10-
NEXT_PUBLIC_LARK_APP_ID =
9+
NEXT_PUBLIC_LARK_API_HOST = https://open.feishu.cn/open-apis/
10+
NEXT_PUBLIC_LARK_APP_ID = cli_a2c7771153f8900c
11+
NEXT_PUBLIC_LARK_WIKI_URL = https://idea2app.feishu.cn/wiki/space/7318346900506181660

models/Document.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { DocumentModel } from 'mobx-lark';
2+
3+
import { lark } from '../pages/api/Lark/core';
4+
5+
export class MyDocumentModel extends DocumentModel {
6+
client = lark.client;
7+
}
8+
9+
export default new MyDocumentModel();

models/Wiki.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { WikiNodeModel } from 'mobx-lark';
2+
3+
import { lark } from '../pages/api/Lark/core';
4+
import { LarkWikiDomain, LarkWikiId } from './configuration';
5+
6+
export class MyWikiNodeModel extends WikiNodeModel {
7+
client = lark.client;
8+
}
9+
10+
export default new MyWikiNodeModel(LarkWikiDomain, LarkWikiId);

models/configuration.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ export const LarkAppMeta = {
2121
id: process.env.NEXT_PUBLIC_LARK_APP_ID!,
2222
secret: process.env.LARK_APP_SECRET!,
2323
};
24+
25+
const { hostname, pathname } = new URL(process.env.NEXT_PUBLIC_LARK_WIKI_URL!);
26+
27+
export const LarkWikiDomain = hostname;
28+
export const LarkWikiId = pathname.split('/').pop()!;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"mobx": "^6.13.7",
3838
"mobx-github": "^0.3.11",
3939
"mobx-i18n": "^0.7.1",
40-
"mobx-lark": "^2.2.0",
40+
"mobx-lark": "^2.4.0-rc.10",
4141
"mobx-react": "^9.2.0",
4242
"mobx-react-helper": "^0.5.1",
4343
"mobx-restful": "^2.1.0",

pages/wiki/[node_token].tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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;

pages/wiki/index.tsx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { WikiNode } from 'mobx-lark';
2+
import { GetStaticProps } from 'next';
3+
import { FC } from 'react';
4+
import { Container } from 'react-bootstrap';
5+
6+
import { PageHead } from '../../components/Layout/PageHead';
7+
import wikiStore from '../../models/Wiki';
8+
import { lark } from '../api/Lark/core';
9+
10+
export const getStaticProps: GetStaticProps = async () => {
11+
await lark.getAccessToken();
12+
13+
const nodes = await wikiStore.getAll();
14+
15+
return { props: { nodes } };
16+
};
17+
18+
const WikiIndexPage: FC<{ nodes: WikiNode[] }> = ({ nodes }) => (
19+
<Container>
20+
<PageHead title="Wiki" />
21+
22+
<h1>Wiki</h1>
23+
24+
<ol>
25+
{nodes.map(({ node_token, title }) => (
26+
<li key={node_token}>
27+
<a href={`/wiki/${node_token}`}>{title}</a>
28+
</li>
29+
))}
30+
</ol>
31+
</Container>
32+
);
33+
34+
export default WikiIndexPage;

pnpm-lock.yaml

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)