Skip to main content

Tags

Support for tags in the yaml-metadata in the header of markdown files.

Extracts this metadata and creates a "Tags" page which lists all tags and all pages for each tag.

Quick Demo

Install this plugin (it will also install mkdocs if required)

pip install mkdocs-plugin-tags

Create a new documentation folder:

mkdocs new demo

Edit the .md files to add initial metadata. Currently, the metadata has to be enclosed in --- lines, and must include a title: property (otherwise the page will appear as "untitled" in the tags page). So, for example:

cd demo
cd docs
cat > index.md
---
title: Welcome
tags:
 - testing
 - unimportant
---
# Welcome to MkDocs

For full documentation visit [mkdocs.org](https://mkdocs.org).

^D

Edit mkdocs.yml to include this plugin:

plugins:
  - tags:

Run the server:

mkdocs serve --livereload

Visit the URL /tags (it should appear in the nav panel). This is an auto-generated page which contains the tags as level 2 headers, and under each tag, a listing of the pages which declare that tag in the metadata section.

example screenshot

How it works

On each build (even with --livereload), all the .md files composing the site are scanned, their "triple-dash-delimted" yaml header is extracted and parsed, and the list of tags is collected.

After that, a new temporal file is created (by default in aux/tags.md, but this is customizable) which contains the generated tags page, in markdown format. This file is not in the documents folder to avoid retriggering a build, but it is added to the list of files to be converted to HTML by mkdocs.

Customization

The layout of the tags page is a markdown file with jinja2 embedded contents. The package provides such a template by default, with the following content:

---
title: Tags
---
# Contents grouped by tag

{% for tag, pages in tags %}

## <span class="tag">{{tag}}</span>
{%  for page in pages %}
  * [{{page.title}}]({{page.filename}})
{% endfor %}

{% endfor %}

You can style the h2.tag element via CSS, if you want.

You can also provide your own markdown template, in case that you want a different layout or metadata. The page object contains all the metadata in a mkdocs page, and in addition a .filename attribute, which contains the file name of the source of the page (relative to the docs folder), which can be used to link to that page.

The full customizable options for the plugin are:

  • tags_folder: Folder in which the auxiliar tags markdown file will be written (aux by default, relative to the folder in which mkdocs is invoked). It can be set to an absolute path, such as /tmp/mysite/aux. The required folders are created.
  • tags_template: path to the file which contains the markdown-jinja template for the tags page. It is None by default, which means that the package-provided template is used. It can be an absolute path, or relative to the folder in which mkdocs is run.
  • css_name: this allows you to pick what name styles the tag that appears on the top of the page that contains a tag. This way things won't be overloaded

For example, this can be put at mkdocs.yaml:

plugins:
    - search
    - tags:
        tags_folder: /tmp/mysite/aux
        tags_template: docs/theme/tags.md.template

Metadata

Release files for mkdocs-plugin-tags 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mkdocs-plugin-tags 1.0.2
File Size Uploaded
mkdocs-plugin-tags-1.0.2.tar.gz 28.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mkdocs-plugin-tags 1.0.2
File Interpreter ABI Platform
mkdocs_plugin_tags-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 41.6 kB

Release files / mkdocs-plugin-tags-1.0.2.tar.gz

Download URL mkdocs-plugin-tags-1.0.2.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
b1f9ebfad3cf0fe03348ece1b20fe296331112090be4a6aec4f5d30fdf6ff927
BLAKE2b-256 checksum
How to use checksums
f04d54bc648da0111f16690a93c4109e29adf1ab8de05c75ed290f7df6fc1fcf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release files / mkdocs_plugin_tags-1.0.2-py3-none-any.whl

Download URL mkdocs_plugin_tags-1.0.2-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
526629f7135b9d1ac5c32f55857d14e57bd9e1ac4580b352c1e7e915fdfaae9e
BLAKE2b-256 checksum
How to use checksums
28a0f7c36e98556e12e24522c2ef398f6b2d34f097f76b64cad3b18f09b94542
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page