Update LLM route handling and improve URL validation

### Summary of Changes
- Set `revalidate` to false for statically generated page content paths in `route.ts`.
- Updated the redirect URL in the LLM route to point to `/llms.txt` instead of the root.
- Enhanced URL validation in `llms.txt` to ensure proper prefixes for documentation and API pages, throwing errors for unexpected URLs.

These changes improve the routing logic and ensure better handling of page URLs.
This commit is contained in:
mantrakp04 2026-03-23 10:36:26 -07:00
parent 349ff27eb9
commit cf657cc2ec
3 changed files with 11 additions and 3 deletions

View File

@ -19,7 +19,7 @@ export async function GET(
}
if (!page) {
return NextResponse.redirect(new URL('/', request.url), 307);
return NextResponse.redirect(new URL('/llms.txt', request.url), 307);
}
try {

View File

@ -12,14 +12,20 @@ export async function GET(request: Request) {
const apiBaseUrl = `${origin}/llms/api/`;
for (const page of source.getPages()) {
const relativeUrl = page.url.replace(/^\/docs\/?/, '');
if (page.url !== '/docs' && !page.url.startsWith('/docs/')) {
throw new Error(`Unexpected page URL "${page.url}" in docs source — expected "/docs" or "/docs/..." prefix`);
}
const relativeUrl = page.url === '/docs' ? '' : page.url.slice('/docs/'.length);
if (relativeUrl !== '') {
docsUrls.add(relativeUrl);
}
}
for (const page of apiSource.getPages()) {
const relativeUrl = page.url.replace(/^\/api\/?/, '');
if (page.url !== '/api' && !page.url.startsWith('/api/')) {
throw new Error(`Unexpected page URL "${page.url}" in API source — expected "/api" or "/api/..." prefix`);
}
const relativeUrl = page.url === '/api' ? '' : page.url.slice('/api/'.length);
if (relativeUrl !== '') {
apiUrls.add(relativeUrl);
}

View File

@ -2,6 +2,8 @@ import { NextResponse, type NextRequest } from 'next/server';
import { getLLMText } from '../../../../lib/get-llm-text';
import { apiSource, source } from '../../../../lib/source';
// revalidate = false applies only to the statically generated page content paths
// (those emitted by generateStaticParams). The empty-slug redirect is always dynamic.
export const revalidate = false;
function resolvePage(slug: string[] | undefined) {