Files
zitadel/apps/docs/lib/source.ts
Florian ForsterandGitHub 24d0f34f39 perf: optimize docs static generation cost (#12108)
## Summary
- Switch the docs catch-all route to full static generation and prebuild
both latest and versioned docs paths.
- Prebuild OG images for all docs pages, make sitemap and LLM export
static, and remove nondeterministic sitemap timestamps.
- Reduce build-time overhead by memoizing docs sidebar trees and
skipping processed markdown generation for versioned docs.

## Testing
- `pnpm nx run @zitadel/docs:build`
- `pnpm nx run @zitadel/docs:lint`
- `pnpm nx run @zitadel/docs:check-types`
- Verified the prerender manifest contains 8,816 prerendered routes,
3,293 versioned docs routes, 4,406 OG routes, and zero revalidating docs
routes.
2026-04-27 15:34:00 +00:00

61 lines
1.8 KiB
TypeScript

import { docs, versions } from '../.source/server';
import { loader } from 'fumadocs-core/source';
import { lucideIconsPlugin } from 'fumadocs-core/source/lucide-icons';
const DOCS_BASE_PATH = '/docs';
// See https://fumadocs.dev/docs/headless/source-api for more info
export const source = loader({
baseUrl: '/',
source: docs.toFumadocsSource(),
plugins: [lucideIconsPlugin()],
});
export const versionSource = loader({
baseUrl: '/',
source: versions.toFumadocsSource(),
plugins: [lucideIconsPlugin()],
});
type LatestPage = ReturnType<typeof source.getPages>[number];
export type DocPage =
| LatestPage
| ReturnType<typeof versionSource.getPages>[number];
export function getPage(slugs: string[] | undefined) {
const safeSlugs = slugs || [];
// If the first slug matches a known version pattern (e.g., starts with 'v' and is in our list), use versionSource
// For simplicity, we check if the page exists in versionSource first if it looks like a version
if (safeSlugs.length > 0 && safeSlugs[0].startsWith('v')) {
const page = versionSource.getPage(safeSlugs);
if (page) return { page, source: versionSource };
}
return { page: source.getPage(safeSlugs), source: source };
}
export function getAllDocPages(): DocPage[] {
return [...source.getPages(), ...versionSource.getPages()];
}
export function generateAllDocParams() {
return [...source.generateParams(), ...versionSource.generateParams()];
}
export function getPageImage(page: DocPage) {
const segments = [...page.slugs, 'image.png'];
return {
segments,
url: `${DOCS_BASE_PATH}/og/docs/${segments.join('/')}`,
};
}
export async function getLLMText(page: LatestPage) {
const processed = await page.data.getText('processed');
return `# ${page.data.title}
${processed}`;
}