入门
推出 Fumadocs MDX,Fumadocs 的官方内容来源。
介绍
🌐 Introduction
Fumadocs MDX 是一个将内容转换为类型安全数据的工具,类似于内容集合。
🌐 Fumadocs MDX is a tool to transform content into type-safe data, similar to Content Collections.
它不是一个完整的内容管理系统,而是一个用于 React 框架的内容处理层,你可以用它来处理博客文章和其他内容。
🌐 It is not a full CMS but rather a content processing layer for React frameworks, you can use it to handle blog posts and other contents.
什么是集合?
🌐 What is a Collection?
集合 指包含某种类型文件的集合。你可以在配置文件(source.config.ts)中定义集合。
Fumadocs MDX 将集合转换为类型安全的数据,可在你的应用中访问。可用集合:
🌐 Fumadocs MDX transforms collections into type-safe data, accessible in your app. Available collections:
将 Markdown 和 MDX 文件编译为 React 服务器组件,并提供实用属性,例如 目录。
🌐 Compile Markdown & MDX files into a React Server Component, with useful properties like Table of Contents.
import { defineCollections } from 'fumadocs-mdx/config';
export const test = defineCollections({
type: 'doc',
dir: 'content/docs',
});将 YAML/JSON 文件转换为数据数组。
🌐 Transform YAML/JSON files into an array of data.
import { defineCollections } from 'fumadocs-mdx/config';
export const test = defineCollections({
type: 'meta',
dir: 'content/docs',
});将 meta 和 doc 集合组合,这是 Fumadocs 所需的。
🌐 Combination of meta and doc collections, which is needed for Fumadocs.
import { defineDocs } from 'fumadocs-mdx/config';
export const docs = defineDocs({
dir: 'content/docs',
docs: {
// options for `doc` collection
},
meta: {
// options for `meta` collection
},
});例如,doc 集合会转换 .md 和 .mdx 文件:
🌐 For example, a doc collection will transform the .md and .mdx files:
我们将在访问集合中讲解如何访问集合输出。
🌐 We will cover in Accessing Collections later on how to access collection outputs.
安装
🌐 Installation
在以下位置配置 Fumadocs MDX:
🌐 Configure Fumadocs MDX on:
Next.js
在 Next.js 中使用 Fumadocs MDX。
Vite
在 Vite 中使用 Fumadocs MDX。
运行时加载器
在 JavaScript 运行时中使用 Fumadocs MDX。
常见问题
🌐 FAQ
内置属性
🌐 Built-in Properties
这些属性默认从 MDX 文件导出。
🌐 These properties are exported from MDX files by default.
| 属性 | 描述 |
|---|---|
frontmatter | 前言 |
toc | 目录 |
structuredData | 结构化数据,有助于实现搜索 |
extractedReferences | 用于分析 hrefs 引用 |
自定义前言部分
🌐 Customise Frontmatter
使用 schema 选项传递验证模式以验证 frontmatter,并定义其输出属性。
🌐 Use the schema option to pass a validation schema to validate frontmatter and define its output properties.
自定义 MDX 编译器
🌐 Customise MDX Compiler
Fumadocs MDX 使用 MDX 编译器 将 MDX 文件编译成 JavaScript 文件。 默认预设 默认包含一组插件和配置。
🌐 Fumadocs MDX uses MDX Compiler to compile MDX files into JavaScript files. The default preset includes a set of plugins and configurations out-of-the-box.
🌐 You can customise it on Global Config or Collection Config.
Last updated on
