内容生成器
Python
从 Python 生成文档
实验性的
对 Python 文档生成的支持仍处于实验阶段,请谨慎使用。
安装
🌐 Setup
npm install fumadocs-python shiki生成文档
🌐 Generate Docs
首先安装 Python 命令,我们需要它从你的 Python 包中收集文档。
🌐 Install the Python command first, we need it to collect docs from your Python package.
pip install ./node_modules/fumadocs-python以 JSON 格式生成文档:
🌐 Generate the docs as a JSON:
fumapy-generate your-package-name
# for example
fumapy-generate httpx使用以下脚本将 JSON 转换为 MDX:
🌐 Use the following script to convert JSON into MDX:
import { rimraf } from 'rimraf';
import * as Python from 'fumadocs-python';
import * as fs from 'node:fs/promises';
// output JSON file path
const jsonPath = './httpx.json';
async function generate() {
const out = 'content/docs/(api)';
// clean previous output
await rimraf(out);
const content = JSON.parse((await fs.readFile(jsonPath)).toString());
const converted = Python.convert(content, {
baseUrl: '/docs',
});
await Python.write(converted, {
outDir: out,
});
}
void generate();小心
虽然大多数文档生成器使用 Markdown 或 reStructuredText,但 Fumadocs 使用 MDX。在运行之前,请确保你的文档符合 MDX 语法。
MDX 组件
🌐 MDX Components
添加组件。
🌐 Add the components.
import defaultMdxComponents from 'fumadocs-ui/mdx';
import type { MDXComponents } from 'mdx/types';
import * as Python from 'fumadocs-python/components';
export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...defaultMdxComponents,
...Python,
...components,
};
}添加样式:
🌐 Add styles:
@import 'tailwindcss';
@import 'fumadocs-ui/css/neutral.css';
@import 'fumadocs-ui/css/preset.css';
@import 'fumadocs-python/preset.css';Last updated on
