跳至內容
Fumadocs

伺服器入口

在伺服器端存取集合的輸出。

使用方式

雖然您可以直接從進入點檔案存取集合,但我們建議搭配 loader() 使用。

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

// 原始集合
console.log(docs);

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

範例

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

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

if (page) {
  // 存取頁面資料
  console.log(page.data);

  // 也可以存取 frontmatter 屬性
  console.log(page.data.title);
}

若要算繪頁面 (於 RSC 中) ,請將 page.data.body 當作元件使用。

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

const MDX = page.data.body;

// 透過 `components` prop 設定您的 MDX 元件
return <MDX components={getMDXComponents()} />;

How is this guide?

最後更新於