Skip to content

Commit 78a9942

Browse files
committed
fix: ci
1 parent 0ccfacb commit 78a9942

8 files changed

Lines changed: 140 additions & 12 deletions

File tree

blocksuite/docs-site/.vitepress/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ export default defineConfig({
120120

121121
search: {
122122
provider: 'local',
123+
options: {
124+
_render(src, env, md) {
125+
if (env.relativePath.startsWith('api/')) {
126+
return '';
127+
}
128+
return md.render(src, env);
129+
},
130+
},
123131
},
124132
},
125133
markdown: {

blocksuite/docs-site/.vitepress/sidebar.ts

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import { existsSync, readdirSync } from 'node:fs';
2+
import { join, parse } from 'node:path';
3+
14
import type { DefaultTheme } from 'vitepress';
25

36
export const guide: DefaultTheme.NavItem[] = [
@@ -100,17 +103,48 @@ export const guide: DefaultTheme.NavItem[] = [
100103
export const reference: DefaultTheme.NavItem[] = [
101104
{
102105
text: 'API Reference',
103-
items: [
104-
{ text: '@blocksuite/store', link: 'api/@blocksuite/store/index' },
105-
{
106-
text: '@blocksuite/block-std',
107-
link: 'api/@blocksuite/block-std/index',
108-
},
109-
{ text: '@blocksuite/inline', link: 'api/@blocksuite/inline/index' },
110-
],
106+
items: getApiReferenceItems(),
111107
},
112108
];
113109

110+
function getApiReferenceItems(): DefaultTheme.NavItem[] {
111+
const apiDir = join(process.cwd(), 'api', '@blocksuite');
112+
113+
if (!existsSync(apiDir)) {
114+
return [
115+
{ text: '@blocksuite/store', link: 'api/@blocksuite/store' },
116+
{ text: '@blocksuite/std', link: 'api/@blocksuite/std/index' },
117+
{ text: '@blocksuite/affine', link: 'api/@blocksuite/affine' },
118+
];
119+
}
120+
121+
return readdirSync(apiDir, { withFileTypes: true })
122+
.flatMap(entry => {
123+
if (entry.isFile() && entry.name.endsWith('.md')) {
124+
const name = parse(entry.name).name;
125+
return [
126+
{ text: `@blocksuite/${name}`, link: `api/@blocksuite/${name}` },
127+
];
128+
}
129+
130+
if (entry.isDirectory()) {
131+
const indexPath = join(apiDir, entry.name, 'index.md');
132+
133+
if (existsSync(indexPath)) {
134+
return [
135+
{
136+
text: `@blocksuite/${entry.name}`,
137+
link: `api/@blocksuite/${entry.name}/index`,
138+
},
139+
];
140+
}
141+
}
142+
143+
return [];
144+
})
145+
.sort((a, b) => a.text.localeCompare(b.text));
146+
}
147+
114148
export const components: DefaultTheme.NavItem[] = [
115149
{
116150
text: 'Introduction',

blocksuite/docs-site/.vitepress/theme/components/Icon.vue renamed to blocksuite/docs-site/.vitepress/theme/components/icon.vue

File renamed without changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { copyFileSync } from 'node:fs';
2+
import { join } from 'node:path';
3+
4+
copyFileSync(
5+
join(process.cwd(), 'pages-worker.mjs'),
6+
join(process.cwd(), '.vitepress', 'dist', '_worker.js')
7+
);

blocksuite/docs-site/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
"license": "MPL-2.0",
99
"type": "module",
1010
"scripts": {
11-
"typedoc": "typedoc --options ./typedoc.json",
11+
"build:deps": "tsc -b ../affine/all",
12+
"typedoc": "yarn run build:deps && typedoc --options ./typedoc.json",
1213
"dev": "yarn run typedoc && yarn exec vitepress dev --port 5200",
1314
"dev:nobuild": "yarn exec vitepress dev --port 5200",
14-
"build": "yarn run typedoc && NODE_OPTIONS=--max-old-space-size=8192 yarn exec vitepress build",
15+
"build": "yarn run typedoc && NODE_OPTIONS=--max-old-space-size=8192 yarn exec vitepress build && node ./copy-pages-worker.mjs",
1516
"preview": "yarn exec vitepress preview"
1617
},
1718
"dependencies": {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const canonicalHost = 'blocksuite.io';
2+
const redirectHosts = new Set([
3+
'blocksuite.affine.pro',
4+
'block-suite.com',
5+
'blocksite.dev',
6+
'blocksite.io',
7+
'blocksuit.dev',
8+
'blocksuit.io',
9+
]);
10+
const apiMemberPathPattern =
11+
/^\/api\/@blocksuite\/(.+)\/(classes|enumerations|functions|interfaces|type-aliases|variables)\/[^/]+\.html$/;
12+
13+
export default {
14+
fetch(request, env) {
15+
const url = new URL(request.url);
16+
17+
if (redirectHosts.has(url.hostname)) {
18+
url.hostname = canonicalHost;
19+
url.protocol = 'https:';
20+
21+
return Response.redirect(url.toString(), 301);
22+
}
23+
24+
if (url.pathname === '/blocksuite-overview.html') {
25+
url.pathname = '/guide/overview.html';
26+
27+
return Response.redirect(url.toString(), 301);
28+
}
29+
30+
const apiMemberPath = url.pathname.match(apiMemberPathPattern);
31+
32+
if (apiMemberPath) {
33+
url.pathname = `/api/@blocksuite/${apiMemberPath[1]}.html`;
34+
35+
return Response.redirect(url.toString(), 301);
36+
}
37+
38+
return env.ASSETS.fetch(request);
39+
},
40+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { Converter } from 'typedoc';
2+
3+
export function load(app) {
4+
app.converter.on(Converter.EVENT_RESOLVE_END, context => {
5+
pruneInheritedReflections(context.project);
6+
});
7+
}
8+
9+
function pruneInheritedReflections(reflection) {
10+
if (reflection.children) {
11+
reflection.children = reflection.children.filter(
12+
child => !child.inheritedFrom
13+
);
14+
reflection.children.forEach(pruneInheritedReflections);
15+
}
16+
17+
if (reflection.groups) {
18+
reflection.groups = reflection.groups
19+
.map(group => ({
20+
...group,
21+
children: group.children.filter(child => !child.inheritedFrom),
22+
}))
23+
.filter(group => group.children.length > 0);
24+
}
25+
26+
if (reflection.categories) {
27+
reflection.categories = reflection.categories
28+
.map(category => ({
29+
...category,
30+
children: category.children.filter(child => !child.inheritedFrom),
31+
}))
32+
.filter(category => category.children.length > 0);
33+
}
34+
}

blocksuite/docs-site/typedoc.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@
1010
"packageOptions": {
1111
"includeVersion": true,
1212
"readme": "none",
13+
"disableSources": true,
14+
"excludeInternal": true,
1315
"excludeExternals": true,
1416
"externalPattern": ["node_modules/**/*"],
1517
"entryPoints": ["src/index.ts"]
1618
},
17-
"plugin": ["typedoc-plugin-markdown"],
19+
"plugin": ["typedoc-plugin-markdown", "./typedoc-remove-inherited.mjs"],
1820
"out": "./api",
1921
"entryPointStrategy": "packages",
2022
"includeVersion": false,
2123
"logLevel": "Error",
2224
"readme": "none",
2325
"name": "BlockSuite API Documentation",
2426
"entryFileName": "index.md",
25-
"outputFileStrategy": "members",
27+
"outputFileStrategy": "modules",
2628
"hidePageHeader": true,
29+
"disableSources": true,
30+
"excludeInternal": true,
2731
"excludePrivate": true,
2832
"excludeProtected": true,
2933
"excludeExternals": true,

0 commit comments

Comments
 (0)