Skip to content

Commit c3da546

Browse files
authored
Add basic support for computed pages types (#2520)
1 parent 79f2d8b commit c3da546

File tree

16 files changed

+96
-36
lines changed

16 files changed

+96
-36
lines changed

bun.lockb

-94.4 KB
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"packageManager": "bun@1.1.18",
1010
"patchedDependencies": {
11-
"@vercel/next@4.3.6": "patches/@vercel%2Fnext@4.3.6.patch"
11+
"@vercel/next@4.3.15": "patches/@vercel%2Fnext@4.3.15.patch"
1212
},
1313
"private": true,
1414
"scripts": {

packages/gitbook/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"clean": "rm -rf ./.next && rm -rf ./public/~gitbook/static"
1717
},
1818
"dependencies": {
19-
"@gitbook/api": "0.64.1",
19+
"@gitbook/api": "^0.66.0",
2020
"@gitbook/cache-do": "workspace:*",
2121
"@gitbook/emoji-codepoints": "workspace:*",
2222
"@gitbook/icons": "workspace:*",
@@ -41,7 +41,7 @@
4141
"katex": "^0.16.9",
4242
"mathjax": "^3.2.2",
4343
"memoizee": "^0.4.15",
44-
"next": "^14.2.5",
44+
"next": "14.2.15",
4545
"next-themes": "^0.2.1",
4646
"nuqs": "^1.17.4",
4747
"object-hash": "^3.0.0",

packages/gitbook/src/app/(site)/(core)/sitemap.xml/route.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ function flattenPages(
8484
return [
8585
...(page.type === 'document' ? [{ page, depth }] : []),
8686
...page.pages.flatMap((child) =>
87-
child.type === 'link' ? [] : flattenPage(child, depth + 1),
87+
child.type === 'document' ? flattenPage(child, depth + 1) : [],
8888
),
8989
];
9090
};
9191

92-
return rootPags.flatMap((page) => (page.type === 'link' ? [] : flattenPage(page, 0)));
92+
return rootPags.flatMap((page) =>
93+
page.type === 'group' || page.type === 'document' ? flattenPage(page, 0) : [],
94+
);
9395
}

packages/gitbook/src/app/(space)/~gitbook/pdf/page.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function selectPages(
315315
return [
316316
{ page, depth },
317317
...page.pages.flatMap((child) => {
318-
if (child.type === 'link') {
318+
if (child.type !== 'document') {
319319
return [];
320320
}
321321

@@ -350,7 +350,7 @@ function selectPages(
350350
}
351351

352352
const allPages = rootPages.flatMap((page) => {
353-
if (page.type === 'link') {
353+
if (page.type !== 'document' && page.type !== 'group') {
354354
return [];
355355
}
356356

packages/gitbook/src/components/DocumentView/Integration/IntegrationBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function IntegrationBlock(props: BlockProps<DocumentBlockIntegratio
6363
renderIntegrationUi(block.data.integration, initialInput),
6464
true,
6565
);
66-
if (!initialOutput) {
66+
if (!initialOutput || initialOutput.type === 'complete') {
6767
return null;
6868
}
6969

packages/gitbook/src/components/PageBody/PageBodyBlankslate.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ export async function PageBodyBlankslate(props: {
1717
}) {
1818
const { page, rootPages, context } = props;
1919

20-
const pages = page.pages.filter((child) => (child.type === 'document' ? !child.hidden : true));
20+
const pages = page.pages.filter((child) =>
21+
child.type === RevisionPageType.Document ? !child.hidden : true,
22+
);
2123
if (!pages.length) {
2224
return null;
2325
}
@@ -43,7 +45,11 @@ export async function PageBodyBlankslate(props: {
4345
/>
4446
);
4547

46-
if (child.type === RevisionPageType.Link) {
48+
if (child.type === RevisionPageType.Computed) {
49+
throw new Error(
50+
'Unexpected computed page, it should have been computed in the API',
51+
);
52+
} else if (child.type === RevisionPageType.Link) {
4753
const resolved = await resolveContentRef(child.target, context);
4854
if (!resolved) {
4955
return null;

packages/gitbook/src/components/TableOfContents/PagesList.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { RevisionPage, RevisionPageDocument, RevisionPageGroup } from '@gitbook/api';
1+
import {
2+
RevisionPage,
3+
RevisionPageDocument,
4+
RevisionPageGroup,
5+
RevisionPageType,
6+
} from '@gitbook/api';
27

38
import { ContentRefContext } from '@/lib/references';
49
import { ClassValue, tcls } from '@/lib/tailwind';
@@ -19,15 +24,21 @@ export function PagesList(props: {
1924
return (
2025
<ul className={tcls('flex', 'flex-1', 'flex-col', 'gap-y-0.5', style)}>
2126
{pages.map((page) => {
22-
if (page.type === 'link') {
27+
if (page.type === RevisionPageType.Computed) {
28+
throw new Error(
29+
'Unexpected computed page, it should have been computed in the API',
30+
);
31+
}
32+
33+
if (page.type === RevisionPageType.Link) {
2334
return <PageLinkItem key={page.id} page={page} context={context} />;
2435
}
2536

2637
if (page.hidden) {
2738
return null;
2839
}
2940

30-
if (page.type === 'group') {
41+
if (page.type === RevisionPageType.Group) {
3142
return (
3243
<PageGroupItem
3344
key={page.id}

packages/gitbook/src/lib/pages.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { Revision, RevisionPage, RevisionPageDocument, RevisionPageGroup } from '@gitbook/api';
1+
import {
2+
Revision,
3+
RevisionPage,
4+
RevisionPageDocument,
5+
RevisionPageGroup,
6+
RevisionPageType,
7+
} from '@gitbook/api';
28

39
export type AncestorRevisionPage = RevisionPageDocument | RevisionPageGroup;
410

@@ -14,7 +20,7 @@ export function resolvePagePath(
1420
ancestors: AncestorRevisionPage[],
1521
): { page: RevisionPageDocument; ancestors: AncestorRevisionPage[] } | undefined => {
1622
for (const page of pages) {
17-
if (page.type === 'link') {
23+
if (page.type === RevisionPageType.Link || page.type === RevisionPageType.Computed) {
1824
continue;
1925
}
2026

@@ -56,7 +62,7 @@ export function resolvePageId(
5662
ancestors: AncestorRevisionPage[],
5763
): { page: RevisionPageDocument; ancestors: AncestorRevisionPage[] } | undefined => {
5864
for (const page of pages) {
59-
if (page.type === 'link') {
65+
if (page.type === RevisionPageType.Link || page.type === RevisionPageType.Computed) {
6066
continue;
6167
}
6268

@@ -139,14 +145,14 @@ function resolvePageDocument(
139145
page: RevisionPage,
140146
ancestors: AncestorRevisionPage[],
141147
): { page: RevisionPageDocument; ancestors: AncestorRevisionPage[] } | undefined {
142-
if (page.type === 'group') {
148+
if (page.type === RevisionPageType.Group) {
143149
const firstDocument = resolveFirstDocument(page.pages, [...ancestors, page]);
144150
if (firstDocument) {
145151
return firstDocument;
146152
}
147153

148154
return;
149-
} else if (page.type === 'link') {
155+
} else if (page.type === RevisionPageType.Link || page.type === RevisionPageType.Computed) {
150156
return undefined;
151157
}
152158

@@ -162,15 +168,15 @@ function flattenPages(
162168
): RevisionPageDocument[] {
163169
const result: RevisionPageDocument[] = [];
164170
for (const page of pages) {
165-
if (page.type === 'link') {
171+
if (page.type === RevisionPageType.Link || page.type === RevisionPageType.Computed) {
166172
continue;
167173
}
168174

169175
if (filter && !filter(page)) {
170176
continue;
171177
}
172178

173-
if (page.type === 'document') {
179+
if (page.type === RevisionPageType.Document) {
174180
result.push(page);
175181
}
176182
result.push(...flattenPages(page.pages, filter));

packages/icons/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"build": "tsc",
3636
"typecheck": "tsc --noEmit",
3737
"dev": "tsc -w",
38-
"clean": "rm -rf ./dist && rm -rf ./src/data"
38+
"clean": "rm -rf ./dist && rm -rf ./src/data",
39+
"unit": "bun test"
3940
},
4041
"bin": {
4142
"gitbook-icons": "./bin/gitbook-icons.js"

0 commit comments

Comments
 (0)