59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { docs } from "collections/server";
|
|
import { loader } from "fumadocs-core/source";
|
|
import { icons as lucide } from "lucide-react";
|
|
import * as simple from "@icons-pack/react-simple-icons";
|
|
import { createElement } from "react";
|
|
import { docsContentRoute, docsImageRoute, docsRoute } from "./shared";
|
|
|
|
// See https://fumadocs.dev/docs/headless/source-api for more info
|
|
export const source = loader({
|
|
baseUrl: docsRoute,
|
|
source: docs.toFumadocsSource(),
|
|
plugins: [],
|
|
icon(icon) {
|
|
if (!icon) {
|
|
// You may set a default icon
|
|
return;
|
|
}
|
|
|
|
if (icon in lucide)
|
|
return createElement(lucide[icon as keyof typeof lucide]);
|
|
if (icon in simple)
|
|
return createElement(simple[icon as keyof typeof simple]);
|
|
},
|
|
});
|
|
|
|
export function getPageImageUrl(page: (typeof source)["$inferPage"]) {
|
|
const segments = [...page.slugs, "image.webp"];
|
|
|
|
return {
|
|
segments,
|
|
url:
|
|
"/" +
|
|
[page.locale, ...docsImageRoute.split("/"), ...segments]
|
|
.filter(Boolean)
|
|
.join("/"),
|
|
};
|
|
}
|
|
|
|
export function getPageMarkdownUrl(page: (typeof source)["$inferPage"]) {
|
|
const segments = [...page.slugs, "content.md"];
|
|
|
|
return {
|
|
segments,
|
|
url:
|
|
"/" +
|
|
[page.locale, ...docsContentRoute.split("/"), ...segments]
|
|
.filter(Boolean)
|
|
.join("/"),
|
|
};
|
|
}
|
|
|
|
export async function getLLMText(page: (typeof source)["$inferPage"]) {
|
|
const processed = await page.data.getText("processed");
|
|
|
|
return `# ${page.data.title} (${page.url})
|
|
|
|
${processed}`;
|
|
}
|