源
为 Loader API 设置源
概览
🌐 Overview
loader() 根据 source 接口接受不同的内容来源。
多个来源
🌐 Multiple Sources
使用 multiple 将多个来源合并为一个。
🌐 Use multiple to combine multiple sources into one.
import { loader, multiple } from 'fumadocs-core/source';
import { openapiPlugin, openapiSource } from 'fumadocs-openapi/server';
import { blog, docs } from 'fumadocs-mdx:collections/server';
import { lucideIconsPlugin } from 'fumadocs-core/source/lucide-icons';
export const source = loader(
multiple({
docs: docs.toFumadocsSource(),
openapi: blog.toFumadocsSource(),
}),
{
baseUrl: '/docs',
},
);要访问每个源特有的属性:
🌐 To access properties exclusive to each source:
const page = source.getPage(['...']);
if (page.data.type === 'docs') {
console.log(page.data);
} else {
console.log(page.data);
}自定义来源
🌐 Custom Source
要接入你自己的内容源,请创建一个 Source 对象。
🌐 To plug your own content source, create a Source object.
由于 Loader API 不依赖文件系统,文件路径只允许像 file.mdx 和 content/file.mdx 这样的虚拟路径,不允许使用 ./file.mdx 和 D://content/file.mdx。
🌐 Since Loader API doesn't rely on file system, file paths only allow virtual paths like file.mdx and content/file.mdx, ./file.mdx and D://content/file.mdx are not allowed.
import { } from 'fumadocs-core/source';
export function (): <{
: { : string; : string[] }; // Your custom type
: { : string; ?: string }; // Your custom type
}> {
return {
: [
{
: 'page',
: 'folder/index.mdx',
: {
: 'Hello World',
// ...
},
},
{
: 'meta',
: 'meta.json',
: {
: 'Docs',
: ['folder'],
// ...
},
},
],
};
}Last updated on
