mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
Renames the public doc-collection method across runtime, types, examples and create-app templates so the API carries no upstream brand. The internal helper and all call sites move together; fumadocs-core package imports are untouched. Pairs with the .docs default outDir change. BREAKING CHANGE: docs.toFumadocsSource() is now docs.toDocsSource(). Co-authored-by: Hanzo Dev <[email protected]>
52 lines
1.3 KiB
TypeScript
52 lines
1.3 KiB
TypeScript
import { loader } from 'fumadocs-core/source';
|
|
import { docs } from 'collections/server';
|
|
import { lucideIconsPlugin } from 'fumadocs-core/source/lucide-icons';
|
|
import { docsRoute } from './shared';
|
|
import { openapi } from './openapi';
|
|
|
|
export const source = loader(
|
|
{
|
|
docs: docs.toDocsSource(),
|
|
openapi: await openapi.staticSource({
|
|
baseDir: 'openapi',
|
|
}),
|
|
},
|
|
{
|
|
baseUrl: docsRoute,
|
|
plugins: [lucideIconsPlugin(), openapi.loaderPlugin()],
|
|
},
|
|
);
|
|
|
|
export function markdownPathToSlugs(segs: string[]) {
|
|
if (segs.length === 0) return [];
|
|
|
|
const out = [...segs];
|
|
out[out.length - 1] = out[out.length - 1].replace(/\.md$/, '');
|
|
if (out.length === 1 && out[0] === 'index') out.pop();
|
|
return out;
|
|
}
|
|
|
|
export function slugsToMarkdownPath(slugs: string[]) {
|
|
const segments = [...slugs];
|
|
if (segments.length === 0) {
|
|
segments.push('index.md');
|
|
} else {
|
|
segments[segments.length - 1] += '.md';
|
|
}
|
|
|
|
return {
|
|
segments,
|
|
url: `${docsRoute}/${segments.join('/')}`,
|
|
};
|
|
}
|
|
|
|
export async function getLLMText(page: (typeof source)['$inferPage']) {
|
|
if (page.type === 'openapi') return JSON.stringify(page.data.getSchema(), null, 2);
|
|
|
|
const processed = await page.data.getText('processed');
|
|
|
|
return `# ${page.data.title} (${page.url})
|
|
|
|
${processed}`;
|
|
}
|