Skip to content

Commit e9fe397

Browse files
authored
Pass shareKey as context while fetching space (#2409)
1 parent 32a73b5 commit e9fe397

File tree

14 files changed

+78
-34
lines changed

14 files changed

+78
-34
lines changed

bun.lockb

-832 Bytes
Binary file not shown.

packages/gitbook/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"dependencies": {
1717
"@geist-ui/icons": "^1.0.2",
18-
"@gitbook/api": "^0.56.0",
18+
"@gitbook/api": "^0.58.0",
1919
"@gitbook/react-math": "workspace:*",
2020
"@gitbook/react-openapi": "workspace:*",
2121
"@gitbook/react-contentkit": "workspace:*",

packages/gitbook/src/app/(space)/(content)/[[...pathname]]/page.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export default async function Page(props: {
6464
const withPageFeedback = customization.feedback.enabled;
6565

6666
const contentRefContext: ContentRefContext = {
67+
siteContext: 'siteId' in contentPointer ? contentPointer : null,
6768
space,
6869
revisionId: contentTarget.revisionId,
6970
pages,

packages/gitbook/src/app/(space)/(core)/robots.txt/route.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export const runtime = 'edge';
1414
*/
1515
export async function GET(req: NextRequest) {
1616
const pointer = getContentPointer();
17-
const space = await getSpace(pointer.spaceId);
17+
const space = await getSpace(
18+
pointer.spaceId,
19+
'siteId' in pointer ? pointer.siteShareKey : undefined,
20+
);
1821
const parent =
1922
'siteId' in pointer
2023
? await getSite(pointer.organizationId, pointer.siteId)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export const runtime = 'edge';
1414
* Generate a sitemap.xml for the current space.
1515
*/
1616
export async function GET(req: NextRequest) {
17-
const { pages: rootPages } = await getSpaceContentData(getContentPointer());
17+
const pointer = getContentPointer();
18+
const { pages: rootPages } = await getSpaceContentData(
19+
pointer,
20+
'siteId' in pointer ? pointer.siteShareKey : undefined,
21+
);
1822
const pages = flattenPages(rootPages, (page) => !page.hidden);
1923
const urls = pages.map(({ page, depth }) => {
2024
// Decay priority with depth

packages/gitbook/src/app/(space)/(core)/~gitbook/icon/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function GET(req: NextRequest) {
4646
const spaceId = pointer.spaceId;
4747

4848
const [space, customization] = await Promise.all([
49-
getSpace(spaceId),
49+
getSpace(spaceId, 'siteId' in pointer ? pointer.siteShareKey : undefined),
5050
'siteId' in pointer ? getCurrentSiteCustomization(pointer) : getSpaceCustomization(spaceId),
5151
]);
5252
const parent =

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export const runtime = 'edge';
4242
export async function generateMetadata(): Promise<Metadata> {
4343
const contentPointer = getContentPointer();
4444
const [space, customization] = await Promise.all([
45-
getSpace(contentPointer.spaceId),
45+
getSpace(
46+
contentPointer.spaceId,
47+
'siteId' in contentPointer ? contentPointer.siteShareKey : undefined,
48+
),
4649
'siteId' in contentPointer
4750
? getCurrentSiteCustomization(contentPointer)
4851
: getSpaceCustomization(contentPointer.spaceId),
@@ -72,7 +75,10 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
7275
'siteId' in contentPointer
7376
? getCurrentSiteCustomization(contentPointer)
7477
: getSpaceCustomization(contentPointer.spaceId),
75-
getSpaceContentData(contentPointer),
78+
getSpaceContentData(
79+
contentPointer,
80+
'siteId' in contentPointer ? contentPointer.siteShareKey : undefined,
81+
),
7682
]);
7783
const language = getSpaceLanguage(customization);
7884

@@ -170,6 +176,7 @@ export default async function PDFHTMLOutput(props: { searchParams: { [key: strin
170176
space={space}
171177
page={page}
172178
refContext={{
179+
siteContext: 'siteId' in contentPointer ? contentPointer : null,
173180
space,
174181
revisionId: contentTarget.revisionId,
175182
pages: rootPages,

packages/gitbook/src/app/(space)/fetch.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,19 @@ export function getContentPointer(): ContentPointer | SiteContentPointer {
7171
export async function fetchSpaceData() {
7272
const content = getContentPointer();
7373

74+
const siteShareKey = 'siteId' in content ? content.siteShareKey : undefined;
75+
7476
const [{ space, contentTarget, pages, customization, scripts }, parentSite] = await Promise.all(
7577
'siteId' in content
7678
? [
7779
getCurrentSiteData(content),
7880
fetchParentSite({
7981
organizationId: content.organizationId,
8082
siteId: content.siteId,
81-
siteShareKey: content.siteShareKey,
83+
siteShareKey,
8284
}),
8385
]
84-
: [getSpaceData(content)],
86+
: [getSpaceData(content, siteShareKey)],
8587
);
8688

8789
const parent = await (parentSite ?? fetchParentCollection(space));
@@ -104,9 +106,10 @@ export async function fetchSpaceData() {
104106
*/
105107
export async function fetchPageData(params: PagePathParams | PageIdParams) {
106108
const content = getContentPointer();
109+
const siteShareKey = 'siteId' in content ? content.siteShareKey : undefined;
107110
const { space, contentTarget, pages, customization, scripts } = await ('siteId' in content
108111
? getCurrentSiteData(content)
109-
: getSpaceData(content));
112+
: getSpaceData(content, siteShareKey));
110113

111114
const page = await resolvePage(contentTarget, pages, params);
112115
const [parent, document] = await Promise.all([

packages/gitbook/src/components/Search/server-actions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export const streamAskQuestion = streamResponse(async function* (spaceId: string
165165
const stream = api
166166
.api()
167167
.spaces.streamAskInSpace(spaceId, { query, format: 'document', details: true });
168-
const pagesPromise = api.getSpaceContentData({ spaceId });
168+
const pagesPromise = api.getSpaceContentData({ spaceId }, undefined);
169169

170170
for await (const chunk of stream) {
171171
// We run the AI search and fetch the pages in parallel

packages/gitbook/src/components/SpaceLayout/SpaceLayout.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ import { CONTAINER_STYLE } from '@/components/layout';
1717
import { ColorDebugger } from '@/components/primitives/ColorDebugger';
1818
import { SearchModal } from '@/components/Search';
1919
import { TableOfContents } from '@/components/TableOfContents';
20-
import { ContentPointer, ContentTarget } from '@/lib/api';
20+
import { ContentPointer, ContentTarget, SiteContentPointer } from '@/lib/api';
2121
import { ContentRefContext } from '@/lib/references';
2222
import { tcls } from '@/lib/tailwind';
2323

2424
/**
2525
* Render the entire content of the space (header, table of contents, footer, and page content).
2626
*/
2727
export function SpaceLayout(props: {
28-
content: ContentPointer;
28+
content: ContentPointer | SiteContentPointer;
2929
contentTarget: ContentTarget;
3030
space: Space;
3131
parent: Site | Collection | null;
@@ -50,6 +50,7 @@ export function SpaceLayout(props: {
5050
const withTopHeader = customization.header.preset !== CustomizationHeaderPreset.None;
5151

5252
const contentRefContext: ContentRefContext = {
53+
siteContext: 'siteId' in content ? content : null,
5354
space,
5455
revisionId: contentTarget.revisionId,
5556
pages,

0 commit comments

Comments
 (0)