Skip to content

内置元插件

¥Built-in meta plugin

元插件解决了为文件夹中的所有页面(即项目的子部分)设置元数据(前置内容)的问题,这对于确保某个页面子集具有特定标签、使用自定义模板或归属于作者特别有用。

¥The meta plugin solves the problem of setting metadata (front matter) for all pages in a folder, i.e., a subsection of your project, which is particularly useful to ensure that a certain subset of pages features specific tags, uses a custom template, or is attributed to an author.

客观的

¥Objective

工作原理

¥How it works

该插件会扫描docs 目录中的.meta.yml文件,并以递归方式将这些文件的内容与同一文件夹及其所有子文件夹中包含的所有页面的元数据(头条内容)合并。例如,如果您想将标签Example添加到多个页面,请使用:

¥The plugin scans the docs directory for .meta.yml files, and recursively merges the contents of those files with the metadata (front matter) of all pages that are contained in the same folder and all subfolders. For example, if you want to add the tag Example to multiple pages, use:

.meta.yml
tags:
  - Example

现在,给定以下目录布局,如果将文件存储在名为example的文件夹中,则该文件夹中的所有页面都会收到该标签,而该文件夹外的所有页面都不会受到影响:

¥Now, given the following directory layout, if you store the file in the folder named example, all pages in that folder receive the tag, while all pages outside of the folder remain unaffected:

.
├─ docs/
  ├─ ...
  ├─ example/
    ├─ .meta.yml
    ├─ a.md
    ├─ ...
    └─ z.md
  └─ ...
└─ mkdocs.yml

组合元数据时,列表和字典会递归合并,这意味着您可以将值附加到列表中,并在任意级别的字典中添加或设置特定属性。

¥When combining metadata, lists and dictionaries are recursively merged, which means you can append values to a list and add or set specific properties in a dictionary on arbitrary levels.

何时使用

¥When to use it

虽然该插件本身除了添加和合并元数据之外没有提供太多功能,但它是 Material for MkDocs 提供的许多其他内置插件的完美伴侣。元插件和其他内置插件的一些最强大的组合包括:

¥While the plugin itself doesn't offer much functionality beyond adding and merging metadata, it is a perfect companion for many of the other built-in plugins that Material for MkDocs offers. Some of the most powerful combinations of the meta plugin and other built-in plugins are:

配置

¥Configuration

9.6.0元 – 内置

¥   Built-in social plugin

与所有内置插件一样,元插件的使用非常简单。只需将以下几行添加到mkdocs.yml ,即可同时为多个页面应用元数据:

¥The meta plugin can be used to change the layout for social cards or change specific layout options like background or color for a subset of pages.

plugins:
  - meta

元插件包含在 Material for MkDocs 中,无需安装。

¥   Built-in blog plugin

一般的

¥General

可用的设置如下:

¥The meta plugin allows to automatically associate blog posts with specific authors and categories, ensuring that blog posts are always correctly annotated.


enabled

¥enabled

9.6.0真实

¥   Built-in tags plugin

使用此设置在构建项目时启用或禁用插件。通常不需要指定此设置,但如果您想禁用插件,请使用:

¥The meta plugin makes it possible to ensure that subsections of your project are annotated with specific tags, so they can't be forgotten when adding pages.

plugins:
  - meta:
      enabled: false

元文件

¥Meta file

元文件有以下设置可用:

¥   Built-in search plugin


meta_file

¥meta_file

9.6.0 .meta.yml

¥The meta plugin makes it easy to boost specific sections in search results or to exclude them entirely from being indexed, giving more granular control over search.

使用此设置可以更改插件在扫描文档目录时查找的元文件名。通常不需要更改此设置,但如果您想更改它,请使用:

¥9.6.0 meta – built-in

plugins:
  - meta:
      meta_file: .meta.yml

提供的路径是从文档目录递归解析的。

¥As with all built-in plugins, getting started with the meta plugin is straightforward. Just add the following lines to mkdocs.yml, and start applying metadata for multiple pages at once: