访问集合
服务端
从服务端访问 Fumadocs MDX 集合
服务端入口点允许从服务端访问集合输出。
核心函数
- loader() — 推荐的集合访问方式,包装原始集合并准备在应用中使用
- getPage() — 通过传入 slug 参数数组获取单个页面
基本用法
import { docs } from 'collections/server';
import { loader } from 'fumadocs-core/source';
export const source = loader({
baseUrl: '/docs',
source: docs.toFumadocsSource(),
});对于非标准集合(如博客文章),使用独立的转换函数:
import { toFumadocsSource } from 'fumadocs-mdx/runtime/server';访问页面数据
配置完成后,使用 source 实例检索页面:
const page = source.getPage(['slugs']);
if (page) {
console.log(page.data); // 访问页面元数据
console.log(page.data.title); // frontmatter 属性可用
}渲染内容
对于 React Server Components,将编译后的 MDX body 作为组件渲染:
const MDX = page.data.body;
return <MDX components={getMDXComponents()} />;