Setting up the meta plugin ¶
Introduction ¶
As you can see on the left - side menu, this plugin is placed as the first one. It is because this plugin can be considered as one that influences the way, you will be writing a documentation. So, why it's so essential?
There are a few reasons:
-
Automatic navigation building based on file and directory names. This simplifies a process of a document navigation creation in
mkdocs.yml
file, described in official documentation . -
Based on file meta-data, you can set document:
- URL ,
- creation/update date ,
- document publication state ,
- and some other less important. Most of these options, influence the SEO of the page build using MkDocs.
Probably you are now wondering why 2 quite different functionalities are placed in one plugin?
The answer is not so obvious and a bit technical, but in bigger simplification, it's way simpler and less complex to bound those functionalities together. The main reason for that is how MkDocs internals work. For example, when navigation is built and when final HTML files are generated. Other example could be a document status implementation that influences navigation building, file list creation and
sitemap.xml
creation. This process should be considered as one functionality and splitting it over 2 separate plugins is possible, but it will not only increase code complexity, but also will increase significantly complexity of configuration since many settings used for automatic navigation building are the same for defining file meta-data. So, if we split functionality into 2 separate plugins, the final user (You) will have to maintain consistency in
mkdocs.yml
file. With a single plugin approach, we can reduce this problem to just maintaining a single point of configuration and settings validation.
Important
However, this plugin is not needed for other plugins to work correctly, it's highly recommended to use it.
Meta-data ¶
Markdown documents can contain additional metadata that is not rendered by MkDocs. This metadata is located at the beginning of the file (more information about this you can found in MkDocs documentation in Meta-Data section ).
MkDocs supports 2 main formats of meta-data:
YAML front matter
Since the YAML front matter format for meta-data is used by a wider set of other plugins and tools, this format will be used in this tool documentation.
Document meta-data ¶
As described in the previous section, you can provide additional meta-data that is unique for that document, and can change some behavior of the meta plugin, but not only. Some other MkDocs plugins also utilize these types of settings. One of the plugins is pub-blog or plugins included in Material for MkDocs .
Directory meta-data ¶
The same approach can be taken for setting this up in the case of directories. To provide meta-data values, you have to create a file
README.md
inside the given directory and put the values accepted by this plugin. A list of possible settings can be found below.
Dates ¶
In the metadata, there is a possibility to add two values related to dates.
This defines a value for the document's creation date. It's also used by a blog plugin for blog posts ordering and a meta plugin for updating a sitemap file.
Date format
Currently, the date format is hard-coded and cannot be changed, and is defined according to
Python date format codes
and looks like this:
%Y-%m-%d %H:%M:%S
(example:
2023-06-12 14:16:52
).
Navigation automatic generation ¶
Warning
If the meta plugin is enabled, document navigation is automatically created by the plugin. So if you have your navigation already created, you will have to set up the navigation in the way, how meta plugin is building it. Currently, this is the only way to provide functionality like single document or directories status.
In short, navigation automatic generation works based on alphabetical order of files and directories. If you are using any IDE (like PyCharm , VsCode or Obsidian ) for documents creation and editing, the way of file order you see by default in the project or file browser of the tool, is the order of the files in navigation. Probably the easiest way of file ordering is to provide some prefix with the digits (take a look at this documentation repository for better understanding). The main problem with this approach would be strange names in file URLs and documentation titles on the web page. To solve that problems, the meta plugin uses two meta-data values that are common for document files and directories:
Document publication status ¶
One of the functions provided by the meta plugin is a possibility to set document publication status. Each publication status has some implications for navigation building and links creation.
When the document publication status is set to
true
(or
published
), the document will appear in navigation and link to it, will be visible on the generated web page.
When the document publication status is set to
hidden
, the document will not appear in navigation, but will be generated, and it's possible to create a link to this document or enter a direct URL address.
When the document publication status is set to
false
(or
draft
), the document will not appear in navigation and will not be generated. However, when using local document hosting by issuing the command
mkdocs serve
, each draft document will be generated to help with document creation and visual inspection.
Default document status
If publication status is not set for document, by default status is set to
false
, so the document will not be published accidentally.
Directory publication status ¶
Publication status can also be set for whole directories. This gives you a control over the whole set of documents that are placed in given directories. Each publication status has some implications for navigation building and links creation.
When the publication status is set to
true
(or
published
) in
README.md
file, the directory will appear in navigation and link to it and documents in this directory, will be visible on the generated web page.
When the publication status is set to
hidden
in
README.md
file, the directory will not appear in navigation, but documents in this directory will be generated and could be accessible by internal linking or by passing direct URL address in the web browser.
When the publication status is set to
false
(or
draft
) in
README.md
file, the directory will not appear in navigation and documents in this directory will not be generated. However, when using local document hosting by issuing the command
mkdocs serve
, each directory and documents will be generated to help with document creation and visual inspection.
Default directory status
If publication status is not set for directory, by default status is set to
true
, so there is no need to create
README.md
file in each directory.
Configuration ¶
To enable the built-in meta plugin, the following lines have to be added to
mkdocs.yml
file:
General ¶
Above you can find all possible settings with their default values. You don't have to provide them. Just use them if you want to change some settings. The description of the meaning of given setting, you can find below.
dir_meta_file
File name containing metadata for directories. The default file name is
README.md
because this file name is used by
GitHub
and
GitLab
(the two most popular git repositories providers) as an index files for the directory. By using this name, this file ideally blends into git repository when the whole documentation is stored in one.
Slug ¶
Above you can find all possible settings with their default values. You don't have to provide them. Just use them if you want to change some settings. The description of the meaning of given setting, you can find below.
enabled
Control if slug metadata will be used while document URL is created while generating a web page.
warn_on_missing
MkDocs contains a switch for
strict mode
. This mode forces break of document generation on any warning and if this option is also enabled, it will force check of all documents, containing a
slug
key defined.
key_name
Metadata key name for slug value.
Publication status ¶
Above you can find all possible settings with their default values. You don't have to provide them. Just use them if you want to change some settings. The description of the meaning of given setting, you can find below.
When Material for MkDocs search plugin is enabled, by default, all documents are indexed and searchable (even those that are hidden by this plugin). To exclude hidden files from being searchable, normally you would have to place an additional value in each hidden document. To make things easier for you, the meta plugin handles it for you, and all hidden documents, are excluded from search. You can change this behavior by changing this value.
search_in_draft
When Material for MkDocs search plugin is enabled, by default, all documents are indexed and searchable (even those that are draft by this plugin). To exclude draft files from being searchable, normally you would have to place an additional value in each draft document. To make things easier for you, the meta plugin handles it for you, and all draft documents, are excluded from search. You can change this behavior by changing this value.
file_default
Defines default status of publication for documents. More information about this, you can find on this page in the section document publication status .
file_warn_on_missing
MkDocs contains a switch for
strict mode
. This mode forces break of document generation on any warning and if this option is also enabled, it will force checking all documents, containing a
status
key defined.
dir_default
Defines default status of publication for directories. More information about this, you can find on this page in the section directory publication status .
dir_warn_on_missing
MkDocs contains a switch for
strict mode
. This mode forces break of document generation on any warning and if this option is also enabled, and it will force checking all directories (in fact
README.md
file in directory), containing a
status
key defined.
key_name
Metadata key name for status value.
Title ¶
Above you can find all possible settings with their default values. You don't have to provide them. Just use them if you want to change some settings. The description of the meaning of given setting, you can find below.
key_name
Metadata key name for title value.
Backlinks:
- automatic documents navigation creation ( pub-meta plugin - v1.0.0),
- documents publication status with additional meta-data like URL names, etc. beneficial for SEO ( pub-meta plugin - v1.0.0),
Setting up a blog
When pub-meta plugin is configured and the directory for blog posts is set up, there is nothing more left to be configured. All the things related to creating a navigation section will be handled automatically by the pub-meta plugin.
v1.1.1 - 2023.10.10
> Pub-meta document or directory status metadata key has been renamed from
status
to
publish
. This change solves 2 problems:
> If you want to use old key name, you can do it by changing key name in
mkdocs.yml
file.