mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-15 01:26:01 +00:00
Fix 404 on Markdown pages when a theme is forced (#4685)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"gitbook": patch
|
||||
---
|
||||
|
||||
Fix 404 on Markdown pages (View as Markdown) in site previews and when a theme is forced with `?theme=`.
|
||||
@@ -1125,6 +1125,30 @@ const testCases: TestsCase[] = [
|
||||
).toBeVisible();
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Markdown page with theme cookie',
|
||||
url: async () => {
|
||||
const data = await getSiteAPIToken(
|
||||
'https://gitbook.gitbook.io/test-gitbook-open/'
|
||||
);
|
||||
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set('token', data.apiToken);
|
||||
searchParams.set('theme', 'dark');
|
||||
|
||||
return `url/${getGitBookPreviewURL(`${data.site}/blocks?${searchParams.toString()}`)}`;
|
||||
},
|
||||
screenshot: false,
|
||||
run: async (page) => {
|
||||
// The app opens previews with `?theme=`, which the middleware persists in a cookie.
|
||||
const markdownURL = new URL(page.url());
|
||||
markdownURL.pathname = `${markdownURL.pathname.replace(/\/$/, '')}.md`;
|
||||
markdownURL.search = '';
|
||||
const response = await page.request.get(markdownURL.toString());
|
||||
expect(response.status()).toBe(200);
|
||||
expect(response.headers()['content-type']).toContain('text/markdown');
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'Redirect to app for authentication when missing token',
|
||||
url: async () => {
|
||||
|
||||
@@ -496,7 +496,9 @@ async function serveSiteRoutes(requestURL: URL, request: NextRequest) {
|
||||
themeMode === CustomizationThemeMode.Dark
|
||||
? CustomizationDefaultThemeMode.Dark
|
||||
: CustomizationDefaultThemeMode.Light;
|
||||
} else {
|
||||
} else if (routeTypeFromPathname !== 'static') {
|
||||
// Markdown, llms.txt, RSS and sitemap routes only exist under `sites/static`, so
|
||||
// forcing them dynamic 404s. They don't render a theme anyway. RND-12749.
|
||||
routeType = 'dynamic';
|
||||
requestHeaders.set(MiddlewareHeaders.Theme, themeMode);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user