跳至內容
Fumadocs

手動安裝

將 Fumadocs 加入現有的 Waku 專案。

您也可以使用 Fumadocs CLI 自動完成設定:

npx @fumadocs/cli init

先決條件

繼續之前,請確認您已設定好:

  • Tailwind CSS 4。
  • Fumadocs MDX:請依照 Vite 設定指南操作,並建立 lib/source.ts 等必要檔案。

小提示

Fumadocs 也支援其他內容來源,包括 Content Collections 與無頭式 CMS。

開始使用

安裝套件:

npm i fumadocs-core fumadocs-ui@npm:@fumadocs/base-ui

與範本相同,此指令會將 fumadocs-ui 安裝為 @fumadocs/base-ui 的別名,也就是 Fumadocs UI 的 Base UI 版本。若要使用 Radix UI 版本,請直接安裝 fumadocs-ui,不要使用別名。

樣式

請將以下內容加入您的 Tailwind CSS 檔案:

@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';

Root Provider

請在用戶端元件中,用 Root Provider 包住整個應用程式:

'use client';
import type { ReactNode } from 'react';
import { RootProvider } from 'fumadocs-ui/provider/waku';

export function Provider({ children }: { children: ReactNode }) {
  return <RootProvider>{children}</RootProvider>;
}

路由

請將各版面配置共用的選項放在同一個檔案中:

src/lib/layout.shared.tsx
import type { BaseLayoutProps } from 'fumadocs-ui/layouts/shared';
import { appName, gitConfig } from './shared';

export function baseOptions(): BaseLayoutProps {
  return {
    nav: {
      // JSX supported
      title: appName,
    },
    githubUrl: `https://github.com/${gitConfig.user}/${gitConfig.repo}`,
  };
}

請建立下列檔案:

import defaultMdxComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from 'mdx/types';

export function getMDXComponents(components?: MDXComponents) {
  return {
    ...defaultMdxComponents,
    ...components,
  } satisfies MDXComponents;
}

export const useMDXComponents = getMDXComponents;

declare global {
  type MDXProvidedComponents = ReturnType<typeof getMDXComponents>;
}

搜尋路由採用 ZBSearch,設定方式請參閱文件搜尋。

完成

啟動開發伺服器,即可在 content/docs 中撰寫您的文件:

content/docs/index.mdx
---
title: Hello World
---

## Introduction

I love Fumadocs.

How is this guide?

最後更新於