Skip to content

Commit 4be36a1

Browse files
authored
Merge branch 'main' into brett/tab-measure-fix
2 parents 723cd99 + e8e979b commit 4be36a1

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

bun.lock

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"@tsconfig/strictest": "^2.0.6",
4949
"@tsconfig/node20": "^20.1.6",
5050
"@base-ui/react": "^1.7.0",
51-
"@gitbook/api": "0.199.0",
51+
"@gitbook/api": "0.200.0",
5252
"@scalar/api-client-react": "^1.3.46",
5353
"@types/react": "^19.0.0",
5454
"@types/react-dom": "^19.0.0",

packages/gitbook/src/components/SitePage/fetch.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { redirect } from 'next/navigation';
1+
import { permanentRedirect, redirect } from 'next/navigation';
22

33
import {
44
SITE_REDIRECT_SOURCE_PATH_MAX_LENGTH,
@@ -89,7 +89,21 @@ async function resolvePage(context: GitBookSiteContext, params: PagePathParams |
8989
})
9090
));
9191
if (resolvedSiteRedirect) {
92-
return redirect(linker.toLinkForContent(resolvedSiteRedirect.target));
92+
const destination = linker.toLinkForContent(resolvedSiteRedirect.target);
93+
const isPublicLiveContext =
94+
!shareKey &&
95+
!context.changeRequest &&
96+
!context.preview &&
97+
context.revisionId === context.space.revision &&
98+
!context.isLoggedInVisitor;
99+
if (
100+
resolvedSiteRedirect.redirect?.permanent &&
101+
!resolvedSiteRedirect.redirect.draft &&
102+
isPublicLiveContext
103+
) {
104+
return permanentRedirect(destination);
105+
}
106+
return redirect(destination);
93107
}
94108
}
95109

packages/gitbook/src/lib/context.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ export type GitBookSiteContext = GitBookSpaceContext & {
201201
/** Whether the request included a visitor token. */
202202
isLoggedInVisitor: boolean;
203203

204+
/** Whether the site is rendered from a preview URL. */
205+
preview: boolean;
206+
204207
/** Whether to display agent instructions in the markdown output. Defaults to true when undefined. */
205208
displayAgentInstructions?: boolean;
206209

@@ -287,6 +290,7 @@ export async function fetchSiteContextByURLLookup(
287290
isFallback: data.isFallback ?? false,
288291
noIndexSearch: data.noIndexSearch ?? false,
289292
isLoggedInVisitor: data.isLoggedInVisitor ?? false,
293+
preview: data.preview ?? false,
290294
displayAgentInstructions: data.displayAgentInstructions,
291295
isAiAgent: data.isAiAgent,
292296
});
@@ -310,6 +314,7 @@ export async function fetchSiteContextByIds(
310314
isFallback: boolean;
311315
noIndexSearch: boolean;
312316
isLoggedInVisitor: boolean;
317+
preview: boolean;
313318
displayAgentInstructions?: boolean;
314319
isAiAgent?: boolean;
315320
}
@@ -439,6 +444,7 @@ export async function fetchSiteContextByIds(
439444
isFallback: ids.isFallback,
440445
noIndexSearch: ids.noIndexSearch,
441446
isLoggedInVisitor: ids.isLoggedInVisitor,
447+
preview: ids.preview,
442448
displayAgentInstructions: ids.displayAgentInstructions,
443449
isAiAgent: ids.isAiAgent,
444450
};

0 commit comments

Comments
 (0)