Skip to content

Commit 145f385

Browse files
conico974Nicolas Dorseuil
andauthored
Add pagination for llms-full.txt file (#3619)
Co-authored-by: Nicolas Dorseuil <nicolas@gitbook.io>
1 parent 360aa1c commit 145f385

File tree

4 files changed

+547
-28
lines changed

4 files changed

+547
-28
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import { type RouteLayoutParams, getStaticSiteContext } from '@/app/utils';
4+
import { serveLLMsFullTxt } from '@/routes/llms-full';
5+
6+
export const dynamic = 'force-static';
7+
8+
export async function GET(
9+
_request: NextRequest,
10+
{ params }: { params: Promise<RouteLayoutParams & { page: string }> }
11+
) {
12+
const awaitedParams = await params;
13+
const page = Number(awaitedParams.page);
14+
// If page is not a number, not an integer, or less than 0, return an error
15+
if (Number.isNaN(page) || !Number.isInteger(page) || page < 0) {
16+
return new Response('Invalid page', { status: 400 });
17+
}
18+
const { context } = await getStaticSiteContext(awaitedParams);
19+
return serveLLMsFullTxt(context, page);
20+
}

packages/gitbook/src/middleware.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ function encodePathInSiteContent(rawPathname: string): {
540540
};
541541
}
542542

543+
// We skip encoding for paginated llms-full.txt pages (i.e. llms-full.txt/100)
544+
if (pathname.match(/^llms-full\.txt\/\d+$/)) {
545+
return { pathname, routeType: 'static' };
546+
}
547+
543548
// If the pathname is an embedded page
544549
const embedPage = pathname.match(/^~gitbook\/embed\/page\/(\S+)$/);
545550
if (embedPage) {

0 commit comments

Comments
 (0)