跳到主要内容
版本:Canary 🚧

📦 plugin-content-pages

Docusaurus 的默认页面插件。这个插件的经典模板带有默认配置。这个插件提供了创建页面功能。

Installation

npm install --save @docusaurus/plugin-content-pages
提示

如果你使用预设的@docusaurus/preset-classic,你不需要将这个插件作为依赖项安装。

您可以通过预设选项配置此插件。

配置

接受字段:

名字类型默认描述
pathstring'src/pages'Path to data on filesystem relative to site dir. Components in this directory will be automatically converted to pages.
routeBasePathstring'/'URL route for the pages section of your site. DO NOT include a trailing slash.
includestring[]['**/*.{js,jsx,ts,tsx,md,mdx}']Matching files will be included and processed.
excludestring[]See example configurationNo route will be created for matching files.
mdxPageComponentstring'@theme/MDXPage'Component used by each MDX page.
remarkPlugins[]any[]Remark plugins passed to MDX.
rehypePlugins[]any[]Rehype plugins passed to MDX.
beforeDefaultRemarkPluginsany[][]Custom Remark plugins passed to MDX before the default Docusaurus Remark plugins.
beforeDefaultRehypePluginsany[][]Custom Rehype plugins passed to MDX before the default Docusaurus Rehype plugins.

示例配置

您可以通过预设选项或插件选项来配置这个插件。

提示

大多数 Docusaurus 用户通过预设选项配置这个插件。

如果使用预设,请通过预设选项配置此插件:

docusaurus.config.js
module.exports = {
presets: [
[
'@docusaurus/preset-classic',
{
pages: {
path: "src/pages",
routeBasePath: "",
include: ["**/*.{js,jsx,ts,tsx,md,mdx}"],
exclude: ["**/_*.{js,jsx,ts,tsx,md,mdx}", "**/_*/**", "**/*.test.{js,jsx,ts,tsx}", "**/__tests__/**"],
mdxPageComponent: "@theme/MDXPage",
remarkPlugins: [require("remark-math")],
rehypePlugins: [],
beforeDefaultRemarkPlugins: [],
beforeDefaultRehypePlugins: [],
},
},
],
],
};

Markdown 元数据

Markdown 页面可以使用以下 Markdown 页前元数据字段,在两边用一行---括起来。

接受字段:

名字类型默认描述
titlestringMarkdown titleThe blog post title.
descriptionstringThe first line of Markdown contentThe description of your page, which will become the <meta name="description" content="..."/> and <meta property="og:description" content="..."/> in <head>, used by search engines.
keywordsstring[]undefinedKeywords meta tag, which will become the <meta name="keywords" content="keyword1,keyword2,..."/> in <head>, used by search engines.
imagestringundefinedCover or thumbnail image that will be used when displaying the link to your post.
wrapperClassNamestringClass name to be added to the wrapper element to allow targeting specific page content.
hide_table_of_contentsbooleanfalseWhether to hide the table of contents to the right.
draftbooleanfalseDraft pages will only be available during development.
unlistedbooleanfalseUnlisted pages will be available in both development and production. They will be "hidden" in production, not indexed, excluded from sitemaps, and can only be accessed by users having a direct link.

例子:

---
title: Markdown Page
description: Markdown page SEO description
wrapperClassName: markdown-page
hide_table_of_contents: false
draft: true
---

Markdown page content

i18n

首先阅读i18n 介绍

翻译文件位置

  • Base path: website/i18n/[locale]/docusaurus-plugin-content-pages
  • Multi-instance path: website/i18n/[locale]/docusaurus-plugin-content-pages-[pluginId]
  • JSON files: extracted with docusaurus write-translations
  • Markdown files: website/i18n/[locale]/docusaurus-plugin-content-pages

示例文件系统结构

website/i18n/[locale]/docusaurus-plugin-content-pages

# translations for website/src/pages
├── first-markdown-page.md
└── second-markdown-page.md