diff --git a/packages/gitbook/src/components/Header/SpacesDropdownMenuItem.tsx b/packages/gitbook/src/components/Header/SpacesDropdownMenuItem.tsx
index 8e790f52b..7e0aa6387 100644
--- a/packages/gitbook/src/components/Header/SpacesDropdownMenuItem.tsx
+++ b/packages/gitbook/src/components/Header/SpacesDropdownMenuItem.tsx
@@ -28,13 +28,15 @@ function useVariantSpaceHref(variantSpace: VariantSpace, currentSpacePath: strin
}
const firstAlternate = metaLinks?.alternates[0];
- const computed = firstAlternate ? {
- pageID: firstAlternate.pageID,
- spaceID: firstAlternate.space?.id
- } : {
- pageID: currentPage?.id,
- spaceID: currentPage?.spaceId
- };
+ const computed = firstAlternate
+ ? {
+ pageID: firstAlternate.pageID,
+ spaceID: firstAlternate.space?.id,
+ }
+ : {
+ pageID: currentPage?.id,
+ spaceID: currentPage?.spaceId,
+ };
// If there is no alternate link, we reconstruct the URL by swapping the space path.
@@ -53,7 +55,7 @@ function useVariantSpaceHref(variantSpace: VariantSpace, currentSpacePath: strin
targetUrl.searchParams.set('fallback', 'true');
- if(computed?.spaceID && computed?.pageID) {
+ if (computed?.spaceID && computed?.pageID) {
targetUrl.searchParams.set('fallbackPageID', computed.pageID);
targetUrl.searchParams.set('fallbackSpaceID', computed.spaceID);
}
@@ -61,7 +63,7 @@ function useVariantSpaceHref(variantSpace: VariantSpace, currentSpacePath: strin
return targetUrl.toString();
}
- if(computed?.spaceID && computed?.pageID) {
+ if (computed?.spaceID && computed?.pageID) {
return `${joinPath(variantSpaceUrl, currentPathname)}?fallback=true&fallbackPageID=${computed.pageID}&fallbackSpaceID=${computed.spaceID}`;
}
diff --git a/packages/gitbook/src/components/SitePage/PageClientLayout.tsx b/packages/gitbook/src/components/SitePage/PageClientLayout.tsx
index 9723fca3e..1424ded9f 100644
--- a/packages/gitbook/src/components/SitePage/PageClientLayout.tsx
+++ b/packages/gitbook/src/components/SitePage/PageClientLayout.tsx
@@ -11,7 +11,7 @@ import type { PageMetaLinks } from './SitePage';
*/
export function PageClientLayout({
pageMetaLinks,
- currentPage
+ currentPage,
}: {
pageMetaLinks: PageMetaLinks | null;
currentPage: {
diff --git a/packages/gitbook/src/components/SitePage/SitePage.tsx b/packages/gitbook/src/components/SitePage/SitePage.tsx
index dd20bbca5..7ae0de885 100644
--- a/packages/gitbook/src/components/SitePage/SitePage.tsx
+++ b/packages/gitbook/src/components/SitePage/SitePage.tsx
@@ -106,7 +106,10 @@ export async function SitePage(props: SitePageProps & { staticRoute: boolean })
staticRoute={props.staticRoute}
/>
-
+
);
@@ -354,7 +357,13 @@ async function resolvePageMetaLinks(
return {
canonical: resolvedCanonical ?? null,
alternates: resolvedAlternates.filter(
- (alt): alt is { href: string; space: AlternateLinkSpace | null, pageID: string | undefined } => !!alt.href
+ (
+ alt
+ ): alt is {
+ href: string;
+ space: AlternateLinkSpace | null;
+ pageID: string | undefined;
+ } => !!alt.href
),
};
}
diff --git a/packages/gitbook/src/components/SitePage/fetch.ts b/packages/gitbook/src/components/SitePage/fetch.ts
index e7051473f..29efef709 100644
--- a/packages/gitbook/src/components/SitePage/fetch.ts
+++ b/packages/gitbook/src/components/SitePage/fetch.ts
@@ -36,7 +36,8 @@ export async function fetchPageData(context: GitBookSiteContext, params: PagePar
* If the path can't be found, we try to resolve it from the API to handle redirects.
*/
async function resolvePage(context: GitBookSiteContext, params: PagePathParams | PageIdParams) {
- const { organizationId, site, space, revision, shareKey, linker, revisionId, fallback } = context;
+ const { organizationId, site, space, revision, shareKey, linker, revisionId, fallback } =
+ context;
if ('pageId' in params) {
return resolvePageId(revision.pages, params.pageId);
@@ -100,12 +101,9 @@ async function resolvePage(context: GitBookSiteContext, params: PagePathParams |
);
if (resolved) {
return resolvePageId(revision.pages, resolved.id);
- } else if(fallback.isFallback && fallback.pageID && fallback.spaceID) {
- return resolveFallbackPage(
- revision.pages,
- fallback.spaceID,
- fallback.pageID
- );
+ // biome-ignore lint/style/noUselessElse: Not useless
+ } else if (fallback.isFallback && fallback.pageID && fallback.spaceID) {
+ return resolveFallbackPage(revision.pages, fallback.spaceID, fallback.pageID);
}
}
diff --git a/packages/gitbook/src/lib/context.ts b/packages/gitbook/src/lib/context.ts
index feae82fb1..78339302d 100644
--- a/packages/gitbook/src/lib/context.ts
+++ b/packages/gitbook/src/lib/context.ts
@@ -29,21 +29,21 @@ import { type GitBookLinker, createLinker, linkerForPublishedURL } from './links
type FallbackData = {
/**
- *
- */
- isFallback: boolean;
+ *
+ */
+ isFallback: boolean;
- /**
- * Space ID of the main space.
- * Only provided for a computed space.
- */
- spaceID?: string;
+ /**
+ * Space ID of the main space.
+ * Only provided for a computed space.
+ */
+ spaceID?: string;
- /**
- * page ID of the main revision.
- * Only provided for a computed revision.
- */
- pageID?: string;
+ /**
+ * page ID of the main revision.
+ * Only provided for a computed revision.
+ */
+ pageID?: string;
};
/**
diff --git a/packages/gitbook/src/lib/pages.ts b/packages/gitbook/src/lib/pages.ts
index 6faba0774..4fc2ddbdb 100644
--- a/packages/gitbook/src/lib/pages.ts
+++ b/packages/gitbook/src/lib/pages.ts
@@ -117,16 +117,16 @@ export function resolvePageId(
}
/**
- *
+ *
* Resolve a page by its related space ID and page ID from the revision pages.
* Related pages are pages that are linked via meta links alternates.
* It uses the metaLinks alternates to find the matching computed page.
* It always use the first alternate to resolve the parent page.
- *
- * @param rootPages
+ *
+ * @param rootPages
* @param relatedSpaceId Space ID of the parent page (i.e. )
- * @param relatedPageId
- * @returns
+ * @param relatedPageId
+ * @returns
*/
export function resolveFallbackPage(
rootPages: Revision['pages'],
@@ -142,10 +142,17 @@ export function resolveFallbackPage(
continue;
}
- if(page.type === RevisionPageType.Document) {
+ if (page.type === RevisionPageType.Document) {
const metaLinksAlternates = page.metaLinks?.alternates;
- if(metaLinksAlternates && metaLinksAlternates.length > 0 && metaLinksAlternates[0]?.kind !== "url") {
- if(metaLinksAlternates[0]?.space === relatedSpaceId && metaLinksAlternates[0]?.page === relatedPageId) {
+ if (
+ metaLinksAlternates &&
+ metaLinksAlternates.length > 0 &&
+ metaLinksAlternates[0]?.kind !== 'url'
+ ) {
+ if (
+ metaLinksAlternates[0]?.space === relatedSpaceId &&
+ metaLinksAlternates[0]?.page === relatedPageId
+ ) {
return resolvePageDocument(page, ancestors);
}
}
@@ -264,7 +271,7 @@ function resolvePageDocument(
return;
}
if (page.type === RevisionPageType.Link || page.type === RevisionPageType.Computed) {
- return undefined;
+ return undefined;
}
return { page, ancestors };
diff --git a/packages/gitbook/src/middleware.ts b/packages/gitbook/src/middleware.ts
index 8f4029003..279f70ba6 100644
--- a/packages/gitbook/src/middleware.ts
+++ b/packages/gitbook/src/middleware.ts
@@ -285,7 +285,7 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
// Extract fallback pageID and spaceID from the URL
// These are used when switching variant spaces to redirect to a specific page if the current path doesn't exist in the new variant.
// Because there is no link between every variant, we need to pass a stable spaceID/pageID to redirect to.
- // They are the first alternate link in the page metadata of the previous variant.
+ // They are the first alternate link in the page metadata of the previous variant.
const fallbackPageID = requestURL.searchParams.get('fallbackPageID');
const fallbackSpaceID = requestURL.searchParams.get('fallbackSpaceID');
@@ -306,11 +306,10 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
imagesContextId: imagesContextId,
contextId: siteURLData.contextId,
fallback: {
- isFallback: requestURL.searchParams.get('fallback') === 'true' ? true : false,
+ isFallback: requestURL.searchParams.get('fallback') === 'true',
...(fallbackPageID ? { pageID: fallbackPageID } : {}),
...(fallbackSpaceID ? { spaceID: fallbackSpaceID } : {}),
- }
-
+ },
};
const requestHeaders = new Headers(request.headers);