Skip to main content
Version: 3.5.1

头元数据

¥Head metadata

自定义头部元数据

¥Customizing head metadata

Docusaurus 自动为你设置 <html><head><body> 中有用的页面元数据。可以使用 Markdown 文件中的 <head> 标签添加额外的元数据(或覆盖现有元数据):

¥Docusaurus automatically sets useful page metadata in <html>, <head> and <body> for you. It is possible to add extra metadata (or override existing ones) with the <head> tag in Markdown files:

markdown-features-head-metadata.mdx
---
id: head-metadata
title: Head Metadata
---

<head>
<html className="some-extra-html-class" />
<body className="other-extra-body-class" />
<title>Head Metadata customized title!</title>
<meta charSet="utf-8" />
<meta name="twitter:card" content="summary" />
<link rel="canonical" href="https://docusaurus.nodejs.cn/docs/markdown-features/head-metadata" />
</head>

# Head Metadata

My text

<head> 声明已作为演示添加到当前 Markdown 文档中。打开浏览器 DevTools 并检查此页面的元数据受到的影响。

¥This <head> declaration has been added to the current Markdown doc as a demo. Open your browser DevTools and check how this page's metadata has been affected.

注意

此功能构建在 Docusaurus <Head> 组件之上。请参阅 react-helmet 了解详尽的文档。

¥This feature is built on top of the Docusaurus <Head> component. Refer to react-helmet for exhaustive documentation.

常规 SEO 不需要这个

内容插件(例如文档和博客)提供了 descriptionkeywordsimage 等前端选项,这些选项将自动应用于 descriptionog:description,而在使用 <head> 标签时,你必须手动声明两个元数据标签。

¥Content plugins (e.g. docs and blog) provide front matter options like description, keywords, and image, which will be automatically applied to both description and og:description, while you would have to manually declare two metadata tags when using the <head> tag.

Markdown 页面描述

¥Markdown page description

Markdown 页面的描述元数据可以用在比头部元数据更多的地方。例如,文档插件的 生成的类别索引 使用文档卡的描述元数据。

¥The Markdown pages' description metadata may be used in more places than the head metadata. For example, the docs plugin's generated category index uses the description metadata for the doc cards.

默认情况下,描述是第一行内容丰富的行,经过一些努力将其转换为纯文本。例如,以下文件...

¥By default, the description is the first content-ful line, with some efforts to convert it to plain text. For example, the following file...

# Title

Main content... May contain some [links](./file.mdx) or **emphasis**.

...将有默认描述“主要内容...可能包含一些链接或强调”。然而,它的设计并不是为了实现完整的功能。如果无法提供合理的描述,你可以通过 Front Matter 明确提供:

¥...will have the default description "Main content... May contain some links or emphasis". However, it's not designed to be fully functional. Where it fails to produce reasonable descriptions, you can explicitly provide one through front matter:

---
description: This description will override the default.
---

# Title

Main content... May contain some [links](./file.mdx) or **emphasis**.