跳到主要内容

1、plugin-content-docs

plugin-content-docs

Provides the Docs functionality and is the default docs plugin for Docusaurus.

提供文档功能,是Docusaurus的默认文档插件。

原文

https://docusaurus.io/zh-CN/docs/api/plugins/@docusaurus/plugin-content-docs

image-20240827210344792

安装

pnpm

pnpm add @docusaurus/plugin-content-docs
提示

If you use the preset @docusaurus/preset-classic, you don't need to install this plugin as a dependency.

You can configure this plugin through the preset options.

如果您使用预设的“@docusaurus/preset-classic”,则不需要将此插件作为依赖项安装。

您可以通过[预设选项]配置此插件(https://docusaurus.io/zh-CN/docs/using-plugins#docusauruspreset-经典)。

配置

接受的字段:

参数类型默认值描述
pathstring'docs'文档内容目录的文件系统路径,相对于站点目录。
editUrl`stringEditUrlFunction`undefined
editLocalizedFilesbooleanfalse编辑 URL 会指向本地化的文件,而不是原始的未翻译文件。 Ignored when editUrl is a function.
editCurrentVersionbooleanfalse编辑 URL 会永远指向当前版本文档而不是历史版本。 Ignored when editUrl is a function.
routeBasePathstring'docs'站点文档部分的 URL 前缀。 DO NOT include a trailing slash. Use / for shipping docs without base path.
tagsBasePathstring'tags'站点标签列表部分的 URL 前缀。 It is prepended to the routeBasePath.
includestring[]['**/*.{md,mdx}']相对于内容路径的 glob 模式列表,匹配到的 Markdown 文件会被构建。
excludestring[]See example configurationGlob 模式列表,匹配到的 Markdown 文件会被排除。 Serves as refinement based on the include option.
sidebarPath`falsestring`undefined
sidebarCollapsiblebooleantrue侧边栏类别是否默认可折叠。 See also Collapsible categories
sidebarCollapsedbooleantrue侧边栏类别是否默认被折叠。 See also Expanded categories by default
sidebarItemsGeneratorSidebarGeneratorOmittedFunction used to replace the sidebar items of type 'autogenerated' with real sidebar items (docs, categories, links...). See also Customize the sidebar items generator
numberPrefixParser`booleanPrefixParser`Omitted
docsRootComponentstring'@theme/DocsRoot'Parent component of all the docs plugin pages (including all versions). Stays mounted when navigation between docs pages and versions.
docVersionRootComponentstring'@theme/DocVersionLayout'Parent component of all docs pages of an individual version (doc pages with sidebars, tags pages). Stays mounted when navigation between pages of that specific version.
docRootComponentstring'@theme/DocRoot'Parent component of all doc pages with sidebars (regular docs pages, category generated index pages). Stays mounted when navigation between such pages.
docItemComponentstring'@theme/DocItem'文档主容器,包括了目录、页面导航等。
docTagsListComponentstring'@theme/DocTagsListPage'标签列表页的根组件
docTagDocListComponentstring'@theme/DocTagDocListPage'「包含某标签的所有文档」页面的根组件。
docCategoryGeneratedIndexComponentstring'@theme/DocCategoryGeneratedIndexPage'自动生成类别索引页的根组件。
remarkPluginsany[][]传递给 MDX 的 Remark 插件。
rehypePluginsany[][]传递给 MDX 的 Rehype 插件。
rehypePluginsany[][]Recma plugins passed to MDX.
beforeDefaultRemarkPluginsany[][]在 Docusaurus 默认 Remark 插件之前传递给 MDX 的自定义 Remark 插件。
beforeDefaultRehypePluginsany[][]在 Docusaurus 默认 Rehype 插件之前传递给 MDX 的自定义 Rehype 插件。
showLastUpdateAuthorbooleanfalse是否显示最后更新文档的作者。
showLastUpdateTimebooleanfalseWhether to display the last date the doc was updated. This requires access to git history during the build, so will not work correctly with shallow clones (a common default for CI systems). With GitHub actions/checkout, usefetch-depth: 0.
breadcrumbsbooleantrue在文档页面上启用或禁用面包屑导航。
disableVersioningbooleanfalse即使存在多个版本,也明确禁用分版功能。 这会让网站只包含当前版本。 Will error if includeCurrentVersion: false and disableVersioning: true.
includeCurrentVersionbooleantrue包含文档的当前版本。
lastVersionstringFirst version in versions.json文档类的导航栏项会默认显示并跳转到的文档版本。
onlyIncludeVersionsstring[]所有版本只包含所有可用版本中的一个子集。
versionsVersionsConfig{}独立自定义每个版本的属性。
tags`stringfalsenull
onInlineTags`'ignore''log''warn'

Types

Example configuration

Markdown前言

Markdown documents can use the following Markdown front matter metadata fields, enclosed by a line --- on either side.

接受的字段:

参数类型默认值描述
idstring文件路径(包括文件夹,不含扩展名)文档的唯一 ID。
titlestringMarkdown title or id你的文档使用的文本标题。 用于页面元数据和多个地方的备用值(侧边栏、下篇/上篇按钮……)。 如果 Markdown 内容没有标题,它会被自动添加到你的文档顶部。
pagination_labelstringsidebar_label or title这篇文档在上一篇/下一篇按钮中显示的文本
sidebar_labelstringtitle这篇文档在侧边栏中显示的文本
sidebar_positionnumber默认排序Controls the position of a doc inside the generated sidebar slice when using autogenerated sidebar items. See also Autogenerated sidebar metadata.
sidebar_class_namestringundefined在使用自动生成侧边栏时,给相应的侧边栏标签一个特殊类名。
sidebar_custom_propsobjectundefinedAssign custom props to the sidebar item referencing this doc
displayed_sidebarstringundefinedForce the display of a given sidebar when browsing the current document. Read the multiple sidebars guide for details.
hide_titlebooleanfalse是否隐藏文档顶部显示的标题。 此选项只会隐藏前言中定义的标题,对于 Markdown 文档顶部的标题没有任何影响。
hide_table_of_contentsbooleanfalse是否隐藏右侧的文档目录。
toc_min_heading_levelnumber2目录中显示的最小标题层级。 必须介于 2 到 6 之间,并且小于等于最大值。
toc_max_heading_levelnumber3目录中显示的最大标题层级。 必须介于 2 和 6。
pagination_next`stringnull`侧边栏的下一个文档
pagination_prev`stringnull`侧边栏的上一个文档
parse_number_prefixesbooleannumberPrefixParser plugin option是否禁用本文档的数字前缀解析。 See also Using number prefixes.
custom_edit_url`stringnull`Computed using the editUrl plugin option
keywordsstring[]undefined用于搜索引擎优化的文档关键词元标签。
descriptionstringMarkdown 正文的第一行The description of your document, which will become the <meta name="description" content="..."/> and <meta property="og:description" content="..."/> in <head>, used by search engines.
imagestringundefinedCover or thumbnail image that will be used as the <meta property="og:image" content="..."/> in the <head>, enhancing link previews on social media and messaging platforms.
slugstring文件路径Allows to customize the document URL (/<routeBasePath>/<slug>). Support multiple patterns: slug: my-doc, slug: /my/path/myDoc, slug: /.
tagsTag[]undefinedA list of strings or objects of two string fields label and permalink to tag to your docs. Strings can be a reference to keys of a tags file (usually tags.yml)
draftbooleanfalseDraft documents will only be available during development.
unlistedbooleanfalseUnlisted documents 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.
last_updateFrontMatterLastUpdateundefinedAllows overriding the last update author/date. Date can be any parsable date string.
type FrontMatterLastUpdate = {date?: string; author?: string};

type Tag = string | {label: string; permalink: string};

示例:

---
id: doc-markdown
title: Docs Markdown Features
hide_title: false
hide_table_of_contents: false
sidebar_label: Markdown #这篇文档在侧边栏中显示的文本
sidebar_position: 3
pagination_label: Markdown features #这篇文档在上一篇/下一篇按钮中显示的文本
custom_edit_url: https://github.com/facebook/docusaurus/edit/main/docs/api-doc-markdown.md
description: How do I find you when I cannot solve this problem
keywords:
- docs
- docusaurus
tags: [docusaurus]
image: https://i.imgur.com/mErPwqL.png
slug: /myDoc
last_update:
date: 1/1/2000
author: custom author name
---

# Markdown Features

My Document Markdown content

Tags File

i18n