docusaurus
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDocusaurus Documentation Skill
Docusaurus 文档技能
Build fast, optimized documentation websites with Docusaurus. This skill covers project setup, versioning, internationalization, and search integration.
使用Docusaurus构建快速、优化的文档网站。本技能涵盖项目搭建、版本管理、国际化以及搜索集成等内容。
When to Use This Skill
何时使用该技能
USE When
适用场景
- Building documentation for open source projects
- Need React components in documentation
- Require multi-version documentation
- Need internationalized documentation
- Want blog functionality alongside docs
- Building developer portals
- Need fast, SEO-optimized static sites
- Want MDX for interactive examples
- 为开源项目构建文档
- 需要在文档中使用React组件
- 要求支持多版本文档
- 需要国际化文档
- 希望在文档旁集成博客功能
- 构建开发者门户
- 需要快速、SEO优化的静态网站
- 希望使用MDX实现交互式示例
DON'T USE When
不适用场景
- Simple single-page documentation (use basic HTML)
- Python-specific API docs with autodoc (use Sphinx)
- No React experience and simple needs (use MkDocs)
- Need real-time collaborative editing (use GitBook)
- Building slide presentations (use Marp)
- 简单的单页文档(使用基础HTML即可)
- Python专属的自动生成API文档(使用Sphinx)
- 无React开发经验且需求简单(使用MkDocs)
- 需要实时协作编辑(使用GitBook)
- 构建幻灯片演示文稿(使用Marp)
Prerequisites
前提条件
Installation
安装
bash
undefinedbash
undefinedCreate new Docusaurus project
Create new Docusaurus project
npx create-docusaurus@latest my-website classic
npx create-docusaurus@latest my-website classic
With TypeScript
With TypeScript
npx create-docusaurus@latest my-website classic --typescript
cd my-website
npm start
undefinednpx create-docusaurus@latest my-website classic --typescript
cd my-website
npm start
undefinedSystem Requirements
系统要求
- Node.js 18.0 or higher
- npm 8 or yarn 1.22+
- Git (for versioning features)
- Node.js 18.0 或更高版本
- npm 8 或 yarn 1.22+
- Git(用于版本管理功能)
Core Capabilities
核心功能
1. Project Structure
1. 项目结构
my-website/
├── blog/ # Blog posts
├── docs/ # Documentation
│ ├── intro.md
│ └── tutorial-basics/
├── src/
│ ├── components/ # React components
│ ├── css/ # Custom styles
│ └── pages/ # Custom pages
├── static/ # Static assets
├── docusaurus.config.js # Main configuration
└── sidebars.js # Sidebar configurationmy-website/
├── blog/ # Blog posts
├── docs/ # Documentation
│ ├── intro.md
│ └── tutorial-basics/
├── src/
│ ├── components/ # React components
│ ├── css/ # Custom styles
│ └── pages/ # Custom pages
├── static/ # Static assets
├── docusaurus.config.js # Main configuration
└── sidebars.js # Sidebar configuration2. Main Configuration
2. 主配置
javascript
// docusaurus.config.js
/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'My Project',
tagline: 'A powerful documentation framework',
favicon: 'img/favicon.ico',
url: 'https://myproject.github.io',
baseUrl: '/',
organizationName: 'myorg',
projectName: 'my-project',
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'warn',
i18n: {
defaultLocale: 'en',
locales: ['en'],
},
presets: [
['classic', {
docs: {
sidebarPath: './sidebars.js',
editUrl: 'https://github.com/myorg/my-project/tree/main/',
showLastUpdateTime: true,
},
blog: {
showReadingTime: true,
postsPerPage: 10,
},
theme: {
customCss: './src/css/custom.css',
},
}],
],
themeConfig: {
navbar: {
title: 'My Project',
logo: { alt: 'Logo', src: 'img/logo.svg' },
items: [
{ type: 'docSidebar', sidebarId: 'tutorialSidebar', label: 'Docs' },
{ to: '/blog', label: 'Blog' },
{ type: 'docsVersionDropdown' },
{ href: 'https://github.com/myorg/my-project', position: 'right' },
],
},
footer: {
style: 'dark',
links: [
{ title: 'Docs', items: [{ label: 'Getting Started', to: '/docs/intro' }] },
{ title: 'Community', items: [{ label: 'Discord', href: 'https://discord.gg/xxx' }] },
],
copyright: `Copyright ${new Date().getFullYear()} My Project.`,
},
prism: {
theme: require('prism-react-renderer').themes.github,
darkTheme: require('prism-react-renderer').themes.dracula,
additionalLanguages: ['bash', 'python', 'yaml'],
},
},
};
module.exports = config;javascript
// docusaurus.config.js
/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'My Project',
tagline: 'A powerful documentation framework',
favicon: 'img/favicon.ico',
url: 'https://myproject.github.io',
baseUrl: '/',
organizationName: 'myorg',
projectName: 'my-project',
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'warn',
i18n: {
defaultLocale: 'en',
locales: ['en'],
},
presets: [
['classic', {
docs: {
sidebarPath: './sidebars.js',
editUrl: 'https://github.com/myorg/my-project/tree/main/',
showLastUpdateTime: true,
},
blog: {
showReadingTime: true,
postsPerPage: 10,
},
theme: {
customCss: './src/css/custom.css',
},
}],
],
themeConfig: {
navbar: {
title: 'My Project',
logo: { alt: 'Logo', src: 'img/logo.svg' },
items: [
{ type: 'docSidebar', sidebarId: 'tutorialSidebar', label: 'Docs' },
{ to: '/blog', label: 'Blog' },
{ type: 'docsVersionDropdown' },
{ href: 'https://github.com/myorg/my-project', position: 'right' },
],
},
footer: {
style: 'dark',
links: [
{ title: 'Docs', items: [{ label: 'Getting Started', to: '/docs/intro' }] },
{ title: 'Community', items: [{ label: 'Discord', href: 'https://discord.gg/xxx' }] },
],
copyright: `Copyright ${new Date().getFullYear()} My Project.`,
},
prism: {
theme: require('prism-react-renderer').themes.github,
darkTheme: require('prism-react-renderer').themes.dracula,
additionalLanguages: ['bash', 'python', 'yaml'],
},
},
};
module.exports = config;3. Sidebar Configuration
3. 侧边栏配置
javascript
// sidebars.js
const sidebars = {
tutorialSidebar: [
'intro',
{
type: 'category',
label: 'Getting Started',
collapsed: false,
items: [
'getting-started/installation',
'getting-started/quick-start',
],
},
{
type: 'category',
label: 'Guides',
link: { type: 'doc', id: 'guides/index' },
items: ['guides/basic-usage', 'guides/advanced'],
},
{
type: 'category',
label: 'Examples',
items: [{ type: 'autogenerated', dirName: 'examples' }],
},
],
};
module.exports = sidebars;javascript
// sidebars.js
const sidebars = {
tutorialSidebar: [
'intro',
{
type: 'category',
label: 'Getting Started',
collapsed: false,
items: [
'getting-started/installation',
'getting-started/quick-start',
],
},
{
type: 'category',
label: 'Guides',
link: { type: 'doc', id: 'guides/index' },
items: ['guides/basic-usage', 'guides/advanced'],
},
{
type: 'category',
label: 'Examples',
items: [{ type: 'autogenerated', dirName: 'examples' }],
},
],
};
module.exports = sidebars;4. Documentation Pages
4. 文档页面
markdown
<!-- docs/intro.md -->
---
id: intro
title: Introduction
sidebar_position: 1
description: Introduction to My Project
---markdown
<!-- docs/intro.md -->
---
id: intro
title: Introduction
sidebar_position: 1
description: Introduction to My Project
---Introduction
Introduction
Welcome to My Project documentation!
Welcome to My Project documentation!
Quick Example
Quick Example
javascript
import { MyProject } from 'my-project';
const project = new MyProject();:::tip Did you know?
You can use admonitions for callouts!
:::
undefinedjavascript
import { MyProject } from 'my-project';
const project = new MyProject();:::tip Did you know?
You can use admonitions for callouts!
:::
undefined5. MDX and React Components
5. MDX 与 React 组件
jsx
// docs/interactive-example.mdx
---
id: interactive-example
title: Interactive Example
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';jsx
// docs/interactive-example.mdx
---
id: interactive-example
title: Interactive Example
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';Interactive Example
Interactive Example
<Tabs>
<TabItem value="js" label="JavaScript" default>
</TabItem>
<TabItem value="py" label="Python">
</TabItem>
</Tabs>
javascript
function hello() {
console.log('Hello!');
}python
def hello():
print("Hello!")<Tabs>
<TabItem value="js" label="JavaScript" default>
</TabItem>
<TabItem value="py" label="Python">
</TabItem>
</Tabs>
javascript
function hello() {
console.log('Hello!');
}python
def hello():
print("Hello!")Inline JSX
Inline JSX
export const Highlight = ({children, color}) => (
<span style={{ backgroundColor: color, padding: '0.2rem', borderRadius: '4px' }}>
{children}
</span>
);
This is <Highlight color="#25c2a0">highlighted</Highlight> text.
undefinedexport const Highlight = ({children, color}) => (
<span style={{ backgroundColor: color, padding: '0.2rem', borderRadius: '4px' }}>
{children}
</span>
);
This is <Highlight color="#25c2a0">highlighted</Highlight> text.
undefined6. Admonitions
6. 提示框(Admonitions)
markdown
:::note
This is a note.
:::
:::tip Pro Tip
Use tips for helpful suggestions.
:::
:::info
Informational content.
:::
:::caution
Warnings about potential issues.
:::
:::danger Critical
Critical warnings.
:::
:::note Custom Title
Admonition with custom title.
:::markdown
:::note
This is a note.
:::
:::tip Pro Tip
Use tips for helpful suggestions.
:::
:::info
Informational content.
:::
:::caution
Warnings about potential issues.
:::
:::danger Critical
Critical warnings.
:::
:::note Custom Title
Admonition with custom title.
:::7. Blog Posts
7. 博客文章
markdown
<!-- blog/2024-01-15-release-v2.md -->
---
slug: release-v2
title: Releasing Version 2.0
authors:
- name: John Doe
title: Lead Developer
image_url: https://github.com/johndoe.png
tags: [release, announcement]
image: /img/blog/v2-release.png
---markdown
<!-- blog/2024-01-15-release-v2.md -->
---
slug: release-v2
title: Releasing Version 2.0
authors:
- name: John Doe
title: Lead Developer
image_url: https://github.com/johndoe.png
tags: [release, announcement]
image: /img/blog/v2-release.png
---Releasing Version 2.0
Releasing Version 2.0
We are excited to announce v2.0!
<!-- truncate -->We are excited to announce v2.0!
<!-- truncate -->What's New
What's New
- Feature 1
- Feature 2
- Feature 1
- Feature 2
Migration Guide
Migration Guide
See our migration guide.
undefinedSee our migration guide.
undefined8. Versioning
8. 版本管理
bash
undefinedbash
undefinedCreate a new version
Create a new version
npm run docusaurus docs:version 1.0
npm run docusaurus docs:version 1.0
Creates:
Creates:
- versioned_docs/version-1.0/
- versioned_docs/version-1.0/
- versioned_sidebars/version-1.0-sidebars.json
- versioned_sidebars/version-1.0-sidebars.json
- versions.json
- versions.json
```javascript
// docusaurus.config.js
module.exports = {
presets: [['@docusaurus/preset-classic', {
docs: {
lastVersion: 'current',
versions: {
current: { label: '2.0 (Next)', path: 'next' },
'1.0': { label: '1.0', path: '1.0' },
},
},
}]],
};
```javascript
// docusaurus.config.js
module.exports = {
presets: [['@docusaurus/preset-classic', {
docs: {
lastVersion: 'current',
versions: {
current: { label: '2.0 (Next)', path: 'next' },
'1.0': { label: '1.0', path: '1.0' },
},
},
}]],
};9. Internationalization (i18n)
9. 国际化(i18n)
javascript
// docusaurus.config.js
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr', 'de'],
localeConfigs: {
en: { label: 'English', htmlLang: 'en-US' },
fr: { label: 'Francais', htmlLang: 'fr-FR' },
},
},
};bash
undefinedjavascript
// docusaurus.config.js
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr', 'de'],
localeConfigs: {
en: { label: 'English', htmlLang: 'en-US' },
fr: { label: 'Francais', htmlLang: 'fr-FR' },
},
},
};bash
undefinedGenerate translation files
Generate translation files
npm run write-translations -- --locale fr
npm run write-translations -- --locale fr
Copy docs to translate
Copy docs to translate
mkdir -p i18n/fr/docusaurus-plugin-content-docs/current
cp -r docs/* i18n/fr/docusaurus-plugin-content-docs/current/
mkdir -p i18n/fr/docusaurus-plugin-content-docs/current
cp -r docs/* i18n/fr/docusaurus-plugin-content-docs/current/
Start in French
Start in French
npm run start -- --locale fr
undefinednpm run start -- --locale fr
undefined10. Search with Algolia
10. 集成 Algolia 搜索
javascript
// docusaurus.config.js
module.exports = {
themeConfig: {
algolia: {
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_SEARCH_API_KEY',
indexName: 'your_index_name',
contextualSearch: true,
},
},
};bash
undefinedjavascript
// docusaurus.config.js
module.exports = {
themeConfig: {
algolia: {
appId: 'YOUR_APP_ID',
apiKey: 'YOUR_SEARCH_API_KEY',
indexName: 'your_index_name',
contextualSearch: true,
},
},
};bash
undefinedAlternative: Local search plugin
Alternative: Local search plugin
npm install @easyops-cn/docusaurus-search-local
undefinednpm install @easyops-cn/docusaurus-search-local
undefined11. Custom CSS
11. 自定义 CSS
css
/* src/css/custom.css */
:root {
--ifm-color-primary: #2e8555;
--ifm-code-font-size: 95%;
--ifm-font-family-base: 'Inter', sans-serif;
}
[data-theme='dark'] {
--ifm-color-primary: #25c2a0;
}
.navbar { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }css
/* src/css/custom.css */
:root {
--ifm-color-primary: #2e8555;
--ifm-code-font-size: 95%;
--ifm-font-family-base: 'Inter', sans-serif;
}
[data-theme='dark'] {
--ifm-color-primary: #25c2a0;
}
.navbar { box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }12. GitHub Pages Deployment
12. GitHub Pages 部署
yaml
undefinedyaml
undefined.github/workflows/deploy.yml
.github/workflows/deploy.yml
name: Deploy to GitHub Pages
on:
push:
branches: [main]
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run build
- uses: actions/upload-pages-artifact@v3
with:
path: build
deploy:
environment:
name: github-pages
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/deploy-pages@v4
```bashname: Deploy to GitHub Pages
on:
push:
branches: [main]
permissions:
contents: read
pages: write
id-token: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
- run: npm ci
- run: npm run build
- uses: actions/upload-pages-artifact@v3
with:
path: build
deploy:
environment:
name: github-pages
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/deploy-pages@v4
```bashManual deployment
Manual deployment
npm run build
npm run deploy
undefinednpm run build
npm run deploy
undefined13. Vercel/Netlify Deployment
13. Vercel/Netlify 部署
json
// vercel.json
{
"buildCommand": "npm run build",
"outputDirectory": "build",
"framework": "docusaurus-2"
}toml
undefinedjson
// vercel.json
{
"buildCommand": "npm run build",
"outputDirectory": "build",
"framework": "docusaurus-2"
}toml
undefinednetlify.toml
netlify.toml
[build]
command = "npm run build"
publish = "build"
undefined[build]
command = "npm run build"
publish = "build"
undefinedIntegration Examples
集成示例
Integration with TypeDoc
与 TypeDoc 集成
bash
npm install typedoc docusaurus-plugin-typedocjavascript
module.exports = {
plugins: [
['docusaurus-plugin-typedoc', {
entryPoints: ['../src/index.ts'],
tsconfig: '../tsconfig.json',
out: 'api',
}],
],
};bash
npm install typedoc docusaurus-plugin-typedocjavascript
module.exports = {
plugins: [
['docusaurus-plugin-typedoc', {
entryPoints: ['../src/index.ts'],
tsconfig: '../tsconfig.json',
out: 'api',
}],
],
};Integration with OpenAPI
与 OpenAPI 集成
bash
npm install docusaurus-plugin-openapi-docs docusaurus-theme-openapi-docsjavascript
module.exports = {
plugins: [
['docusaurus-plugin-openapi-docs', {
id: 'openapi',
config: {
petstore: {
specPath: 'api/openapi.yaml',
outputDir: 'docs/api',
},
},
}],
],
themes: ['docusaurus-theme-openapi-docs'],
};bash
npm install docusaurus-plugin-openapi-docs docusaurus-theme-openapi-docsjavascript
module.exports = {
plugins: [
['docusaurus-plugin-openapi-docs', {
id: 'openapi',
config: {
petstore: {
specPath: 'api/openapi.yaml',
outputDir: 'docs/api',
},
},
}],
],
themes: ['docusaurus-theme-openapi-docs'],
};Best Practices
最佳实践
1. Documentation Structure
1. 文档结构
docs/
├── intro.md
├── getting-started/
│ ├── _category_.json
│ ├── installation.md
│ └── quick-start.md
├── guides/
│ ├── _category_.json
│ ├── index.md
│ └── advanced.md
├── api/
│ └── reference.md
├── faq.md
└── changelog.mdjson
// docs/getting-started/_category_.json
{
"label": "Getting Started",
"position": 1,
"collapsible": true,
"collapsed": false
}docs/
├── intro.md
├── getting-started/
│ ├── _category_.json
│ ├── installation.md
│ └── quick-start.md
├── guides/
│ ├── _category_.json
│ ├── index.md
│ └── advanced.md
├── api/
│ └── reference.md
├── faq.md
└── changelog.mdjson
// docs/getting-started/_category_.json
{
"label": "Getting Started",
"position": 1,
"collapsible": true,
"collapsed": false
}2. SEO Optimization
2. SEO 优化
markdown
---
title: My Page | Brand Name
description: Description for search engines (150-160 chars)
keywords: [keyword1, keyword2]
image: /img/og/my-page.png
---markdown
---
title: My Page | Brand Name
description: Description for search engines (150-160 chars)
keywords: [keyword1, keyword2]
image: /img/og/my-page.png
---3. Content Guidelines
3. 内容规范
markdown
---
id: unique-id
title: Clear Title
sidebar_label: Short Label
description: SEO description
---markdown
---
id: unique-id
title: Clear Title
sidebar_label: Short Label
description: SEO description
---Page Title (H1 - only one)
Page Title (H1 - only one)
Section (H2)
Section (H2)
Subsection (H3)
Subsection (H3)
:::tip Best Practice
Use admonitions appropriately.
:::
See also: Related Page
undefined:::tip Best Practice
Use admonitions appropriately.
:::
See also: Related Page
undefinedTroubleshooting
故障排除
Build Fails with Module Not Found
构建失败:模块未找到
bash
rm -rf node_modules .docusaurus build
npm install
npm run buildbash
rm -rf node_modules .docusaurus build
npm install
npm run buildHot Reload Not Working
热重载不生效
bash
npm run clear
npm run startbash
npm run clear
npm run startBroken Links
链接失效
javascript
module.exports = {
onBrokenLinks: 'warn', // Change from 'throw' for debugging
};javascript
module.exports = {
onBrokenLinks: 'warn', // Change from 'throw' for debugging
};i18n Build Issues
国际化构建问题
bash
npm run build -- --locale en
npm run write-translations -- --locale frbash
npm run build -- --locale en
npm run write-translations -- --locale frDebug Mode
调试模式
bash
DEBUG=docusaurus* npm run build
npm run start -- --port 3001bash
DEBUG=docusaurus* npm run build
npm run start -- --port 3001Algolia Indexing Issues
Algolia 索引问题
javascript
// Check Algolia configuration
module.exports = {
themeConfig: {
algolia: {
appId: 'YOUR_APP_ID', // Not the API key
apiKey: 'SEARCH_ONLY_KEY', // Search-only API key
indexName: 'your_index',
debug: true, // Enable debug mode
},
},
};javascript
// Check Algolia configuration
module.exports = {
themeConfig: {
algolia: {
appId: 'YOUR_APP_ID', // Not the API key
apiKey: 'SEARCH_ONLY_KEY', // Search-only API key
indexName: 'your_index',
debug: true, // Enable debug mode
},
},
};Version Dropdown Not Showing
版本下拉菜单不显示
javascript
// Ensure versions.json exists and navbar is configured
module.exports = {
themeConfig: {
navbar: {
items: [
{ type: 'docsVersionDropdown', position: 'right' },
],
},
},
};javascript
// Ensure versions.json exists and navbar is configured
module.exports = {
themeConfig: {
navbar: {
items: [
{ type: 'docsVersionDropdown', position: 'right' },
],
},
},
};Advanced Configuration
高级配置
Custom Homepage
自定义首页
jsx
// src/pages/index.js
import React from 'react';
import Layout from '@theme/Layout';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import styles from './index.module.css';
function HomepageHeader() {
const { siteConfig } = useDocusaurusContext();
return (
<header className={styles.heroBanner}>
<div className="container">
<h1 className="hero__title">{siteConfig.title}</h1>
<p className="hero__subtitle">{siteConfig.tagline}</p>
<div className={styles.buttons}>
<a className="button button--primary button--lg" href="/docs/intro">
Get Started
</a>
</div>
</div>
</header>
);
}
export default function Home() {
return (
<Layout title="Home" description="Welcome to our documentation">
<HomepageHeader />
<main>
<section className={styles.features}>
<div className="container">
<div className="row">
<Feature title="Easy to Use" description="Simple setup and configuration" />
<Feature title="Powerful" description="Full React and MDX support" />
<Feature title="Fast" description="Optimized for performance" />
</div>
</div>
</section>
</main>
</Layout>
);
}jsx
// src/pages/index.js
import React from 'react';
import Layout from '@theme/Layout';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import styles from './index.module.css';
function HomepageHeader() {
const { siteConfig } = useDocusaurusContext();
return (
<header className={styles.heroBanner}>
<div className="container">
<h1 className="hero__title">{siteConfig.title}</h1>
<p className="hero__subtitle">{siteConfig.tagline}</p>
<div className={styles.buttons}>
<a className="button button--primary button--lg" href="/docs/intro">
Get Started
</a>
</div>
</div>
</header>
);
}
export default function Home() {
return (
<Layout title="Home" description="Welcome to our documentation">
<HomepageHeader />
<main>
<section className={styles.features}>
<div className="container">
<div className="row">
<Feature title="Easy to Use" description="Simple setup and configuration" />
<Feature title="Powerful" description="Full React and MDX support" />
<Feature title="Fast" description="Optimized for performance" />
</div>
</div>
</section>
</main>
</Layout>
);
}Plugin Development
插件开发
javascript
// plugins/my-plugin/index.js
module.exports = function myPlugin(context, options) {
return {
name: 'my-plugin',
async loadContent() {
return { data: 'example' };
},
async contentLoaded({ content, actions }) {
const { createData, addRoute } = actions;
const dataPath = await createData('my-data.json', JSON.stringify(content));
addRoute({
path: '/custom-page',
component: '@site/src/components/CustomPage',
modules: { data: dataPath },
exact: true,
});
},
configureWebpack(config, isServer) {
return {
resolve: {
alias: { '@data': path.resolve(__dirname, 'data') },
},
};
},
};
};javascript
// plugins/my-plugin/index.js
module.exports = function myPlugin(context, options) {
return {
name: 'my-plugin',
async loadContent() {
return { data: 'example' };
},
async contentLoaded({ content, actions }) {
const { createData, addRoute } = actions;
const dataPath = await createData('my-data.json', JSON.stringify(content));
addRoute({
path: '/custom-page',
component: '@site/src/components/CustomPage',
modules: { data: dataPath },
exact: true,
});
},
configureWebpack(config, isServer) {
return {
resolve: {
alias: { '@data': path.resolve(__dirname, 'data') },
},
};
},
};
};Version History
版本历史
v1.0.0 (2026-01-17)
v1.0.0 (2026-01-17)
- Initial skill creation
- Project setup and configuration
- Documentation pages with MDX
- Blog functionality
- Sidebar configuration
- Theme customization
- Versioning setup
- Internationalization (i18n)
- Algolia search integration
- GitHub Pages deployment
- Best practices and troubleshooting
- 初始技能创建
- 项目搭建与配置
- 支持MDX的文档页面
- 博客功能
- 侧边栏配置
- 主题自定义
- 版本管理设置
- 国际化(i18n)
- Algolia搜索集成
- GitHub Pages部署
- 最佳实践与故障排除
Related Resources
相关资源
Build blazing-fast documentation websites with React and MDX.
使用React和MDX构建极速文档网站。