Fumadocs

服务器入口

正在从服务器访问集合输出。

使用

🌐 Usage

虽然你可以直接从入口文件访问集合,但我们建议与 loader() 一起使用。

🌐 While you can access the collections directly from entry file, we suggest using it with loader().

import { docs } from 'fumadocs-mdx:collections/server';
import { loader } from 'fumadocs-core/source';

// raw collection
console.log(docs);

export const source = loader({
  baseUrl: '/docs',
  source: docs.toFumadocsSource(),
});

例子

🌐 Examples

import { source } from '@/lib/source';

const page = source.getPage(['slugs']);

if (page) {
  // access page data
  console.log(page.data);

  // frontmatter properties are also available
  console.log(page.data.title);
}

要在 RSC 上渲染页面,请使用 page.data.body 作为组件。

🌐 To render the page (on RSC), use page.data.body as a component.

import { getMDXComponents } from '@/mdx-components';

const MDX = page.data.body;

// set your MDX components with `components` prop
return <MDX components={getMDXComponents()} />;

Last updated on

On this page