2021-12-16 17:08:57 +01:00
|
|
|
|
# Reference
|
2020-07-22 13:37:14 +02:00
|
|
|
|
|
2021-12-16 17:08:57 +01:00
|
|
|
|
Material for MkDocs is packed with many great features that make technical
|
2022-10-02 16:36:47 +02:00
|
|
|
|
writing a joyful activity. This section of the documentation explains how to set up
|
2021-12-16 17:08:57 +01:00
|
|
|
|
a page, and showcases all available specimen that can be used directly from
|
|
|
|
|
within Markdown files.
|
2020-07-27 14:44:47 +02:00
|
|
|
|
|
2020-07-22 13:37:14 +02:00
|
|
|
|
## Configuration
|
|
|
|
|
|
2020-07-27 13:50:31 +02:00
|
|
|
|
## Usage
|
2020-07-22 19:11:22 +02:00
|
|
|
|
|
2022-12-20 21:21:19 +01:00
|
|
|
|
### Setting the page `title`
|
2020-07-22 19:11:22 +02:00
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
Each page has a designated title, which is used in the navigation sidebar, for
|
|
|
|
|
[social cards] and in other places. While MkDocs attempts to automatically
|
|
|
|
|
determine the title of a page in a [four step process], the title can also be
|
2022-10-02 16:36:47 +02:00
|
|
|
|
explicitly set with the front matter `title` property:
|
2020-07-22 19:11:22 +02:00
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
``` yaml
|
2020-07-23 17:00:20 +02:00
|
|
|
|
---
|
2021-12-11 14:30:07 +01:00
|
|
|
|
title: Lorem ipsum dolor sit amet # (1)!
|
2020-07-23 17:00:20 +02:00
|
|
|
|
---
|
2021-05-30 15:59:13 +02:00
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
# Page title
|
2021-05-30 15:59:13 +02:00
|
|
|
|
...
|
2020-07-22 19:11:22 +02:00
|
|
|
|
```
|
|
|
|
|
|
2022-10-02 16:36:47 +02:00
|
|
|
|
1. This line sets the [`title`][title] inside the HTML document's
|
|
|
|
|
[`head`][head] for the generated page to the given value. Note that the
|
|
|
|
|
site title, which is set via [`site_name`][site_name], is appended with a
|
|
|
|
|
dash.
|
2020-07-22 19:11:22 +02:00
|
|
|
|
|
2022-10-02 16:36:47 +02:00
|
|
|
|
[social cards]: ../setup/setting-up-social-cards.md
|
|
|
|
|
[four step process]: https://www.mkdocs.org/user-guide/writing-your-docs/#meta-data
|
2021-10-10 13:17:39 +02:00
|
|
|
|
[title]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
|
|
|
|
|
[head]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head
|
|
|
|
|
[site_name]: https://www.mkdocs.org/user-guide/configuration/#site_name
|
2020-07-27 13:50:31 +02:00
|
|
|
|
|
2022-12-20 21:21:19 +01:00
|
|
|
|
### Setting the page `description`
|
2020-07-22 19:11:22 +02:00
|
|
|
|
|
2022-10-02 16:36:47 +02:00
|
|
|
|
A Markdown file can include a description that is added to the `meta` tags of
|
2023-09-14 19:09:18 +02:00
|
|
|
|
a page, and is also used for [social cards]. It's a good idea to set a
|
2022-10-02 16:36:47 +02:00
|
|
|
|
[`site_description`][site_description] in `mkdocs.yml` as a fallback value if
|
|
|
|
|
the author does not explicitly define a description for a Markdown file:
|
2020-07-22 19:11:22 +02:00
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
``` yaml
|
2020-07-23 17:00:20 +02:00
|
|
|
|
---
|
2021-12-16 17:08:57 +01:00
|
|
|
|
description: Nullam urna elit, malesuada eget finibus ut, ac tortor. # (1)!
|
|
|
|
|
---
|
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
# Page title
|
2021-12-16 17:08:57 +01:00
|
|
|
|
...
|
|
|
|
|
```
|
|
|
|
|
|
2022-10-02 16:36:47 +02:00
|
|
|
|
1. This line sets the `meta` tag containing the description inside the
|
2021-12-16 17:08:57 +01:00
|
|
|
|
document `head` for the current page to the provided value.
|
|
|
|
|
|
2022-10-02 16:36:47 +02:00
|
|
|
|
[site_description]: https://www.mkdocs.org/user-guide/configuration/#site_description
|
|
|
|
|
|
2022-12-20 21:21:19 +01:00
|
|
|
|
### Setting the page `icon`
|
2021-12-16 17:08:57 +01:00
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
<!-- md:version 9.2.0 -->
|
|
|
|
|
<!-- md:flag experimental -->
|
2021-12-16 17:08:57 +01:00
|
|
|
|
|
|
|
|
|
An icon can be assigned to each page, which is then rendered as part of the
|
2022-10-02 16:36:47 +02:00
|
|
|
|
navigation sidebar, as well as [navigation tabs], if enabled. Use the front
|
|
|
|
|
matter `icon` property to reference an icon, adding the following lines at the
|
|
|
|
|
top of a Markdown file:
|
2021-12-16 17:08:57 +01:00
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
``` yaml
|
2021-12-16 17:08:57 +01:00
|
|
|
|
---
|
|
|
|
|
icon: material/emoticon-happy # (1)!
|
2020-07-23 17:00:20 +02:00
|
|
|
|
---
|
2021-05-30 15:59:13 +02:00
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
# Page title
|
2021-05-30 15:59:13 +02:00
|
|
|
|
...
|
2020-07-22 19:11:22 +02:00
|
|
|
|
```
|
|
|
|
|
|
2022-01-16 17:27:14 +01:00
|
|
|
|
1. Enter a few keywords to find the perfect icon using our [icon search] and
|
|
|
|
|
click on the shortcode to copy it to your clipboard:
|
|
|
|
|
|
|
|
|
|
<div class="mdx-iconsearch" data-mdx-component="iconsearch">
|
|
|
|
|
<input class="md-input md-input--stretch mdx-iconsearch__input" placeholder="Search icon" data-mdx-component="iconsearch-query" value="emoticon happy" />
|
|
|
|
|
<div class="mdx-iconsearch-result" data-mdx-component="iconsearch-result" data-mdx-mode="file">
|
|
|
|
|
<div class="mdx-iconsearch-result__meta"></div>
|
|
|
|
|
<ol class="mdx-iconsearch-result__list"></ol>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2021-12-16 17:08:57 +01:00
|
|
|
|
|
|
|
|
|
[Insiders]: ../insiders/index.md
|
|
|
|
|
[icon search]: icons-emojis.md#search
|
2022-10-02 16:36:47 +02:00
|
|
|
|
[navigation tabs]: ../setup/setting-up-navigation.md#navigation-tabs
|
2021-12-16 17:08:57 +01:00
|
|
|
|
|
2022-12-20 21:21:19 +01:00
|
|
|
|
### Setting the page `status`
|
2022-08-21 19:10:19 +02:00
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
<!-- md:version 9.2.0 -->
|
|
|
|
|
<!-- md:flag experimental -->
|
2022-08-21 19:10:19 +02:00
|
|
|
|
|
|
|
|
|
A status can be assigned to each page, which is then displayed as part of the
|
2023-09-14 19:09:18 +02:00
|
|
|
|
navigation sidebar. First, associate a status identifier with a description by
|
2022-08-21 19:10:19 +02:00
|
|
|
|
adding the following to `mkdocs.yml`:
|
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
extra:
|
|
|
|
|
status:
|
|
|
|
|
<identifier>: <description> # (1)!
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
1. The identifier can only include alphanumeric characters, as well as dashes
|
|
|
|
|
and underscores. For example, if you have a status `Recently added`, you can
|
|
|
|
|
set `new` as an identifier:
|
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
extra:
|
|
|
|
|
status:
|
|
|
|
|
new: Recently added
|
|
|
|
|
```
|
|
|
|
|
|
2022-10-02 16:36:47 +02:00
|
|
|
|
The page status can now be set with the front matter `status` property. For
|
2023-09-14 19:09:18 +02:00
|
|
|
|
example, you can mark a page as `new` with the following lines at the top of a
|
2022-10-02 16:36:47 +02:00
|
|
|
|
Markdown file:
|
2022-08-21 19:10:19 +02:00
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
``` yaml
|
2022-08-21 19:10:19 +02:00
|
|
|
|
---
|
|
|
|
|
status: new
|
|
|
|
|
---
|
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
# Page title
|
2022-08-21 19:10:19 +02:00
|
|
|
|
...
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
The following status identifiers are currently supported:
|
|
|
|
|
|
|
|
|
|
- :material-alert-decagram: – `new`
|
|
|
|
|
- :material-trash-can: – `deprecated`
|
|
|
|
|
|
2023-01-14 20:29:27 +01:00
|
|
|
|
### Setting the page `subtitle`
|
2022-10-02 16:36:47 +02:00
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
<!-- md:sponsors -->
|
|
|
|
|
<!-- md:version insiders-4.25.0 -->
|
|
|
|
|
<!-- md:flag experimental -->
|
2022-10-02 16:36:47 +02:00
|
|
|
|
|
|
|
|
|
Each page can define a subtitle, which is then rendered below the title as part
|
|
|
|
|
of the navigation sidebar by using the front matter `subtitle` property, and
|
|
|
|
|
adding the following lines:
|
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
---
|
|
|
|
|
subtitle: Nullam urna elit, malesuada eget finibus ut, ac tortor
|
|
|
|
|
---
|
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
# Page title
|
2022-10-02 16:36:47 +02:00
|
|
|
|
...
|
|
|
|
|
```
|
|
|
|
|
|
2022-12-20 21:21:19 +01:00
|
|
|
|
### Setting the page `template`
|
2021-12-16 17:08:57 +01:00
|
|
|
|
|
|
|
|
|
If you're using [theme extension] and created a new page template in the
|
2023-09-14 19:09:18 +02:00
|
|
|
|
`overrides` directory, you can enable it for a specific page. Add the following
|
2021-12-16 17:08:57 +01:00
|
|
|
|
lines at the top of a Markdown file:
|
|
|
|
|
|
2022-09-11 19:25:40 +02:00
|
|
|
|
``` yaml
|
2021-12-16 17:08:57 +01:00
|
|
|
|
---
|
|
|
|
|
template: custom.html
|
|
|
|
|
---
|
|
|
|
|
|
2023-09-14 19:09:18 +02:00
|
|
|
|
# Page title
|
2021-12-16 17:08:57 +01:00
|
|
|
|
...
|
|
|
|
|
```
|
|
|
|
|
|
2022-07-17 15:20:08 +02:00
|
|
|
|
??? question "How to set a page template for an entire folder?"
|
|
|
|
|
|
|
|
|
|
With the help of the [built-in meta plugin], you can set a custom template
|
2022-09-11 19:25:40 +02:00
|
|
|
|
for an entire section and all nested pages, by creating a `.meta.yml` file
|
2022-07-17 15:20:08 +02:00
|
|
|
|
in the corresponding folder with the following content:
|
|
|
|
|
|
|
|
|
|
``` yaml
|
|
|
|
|
template: custom.html
|
|
|
|
|
```
|
|
|
|
|
|
2021-12-16 17:08:57 +01:00
|
|
|
|
[theme extension]: ../customization.md#extending-the-theme
|
2023-09-14 19:23:49 +02:00
|
|
|
|
[built-in meta plugin]: ../plugins/meta.md
|
2020-07-27 13:50:31 +02:00
|
|
|
|
|
2021-10-10 13:17:39 +02:00
|
|
|
|
## Customization
|
2021-09-04 15:58:26 +02:00
|
|
|
|
|
2021-10-10 13:17:39 +02:00
|
|
|
|
### Using metadata in templates
|
2020-09-20 11:24:46 +02:00
|
|
|
|
|
2022-12-20 21:21:19 +01:00
|
|
|
|
#### :material-check-all: on all pages
|
2021-05-01 19:04:44 +02:00
|
|
|
|
|
|
|
|
|
In order to add custom `meta` tags to your document, you can [extend the theme
|
2021-10-10 21:04:22 +02:00
|
|
|
|
][theme extension] and [override the `extrahead` block][overriding blocks],
|
2021-10-10 13:17:39 +02:00
|
|
|
|
e.g. to add indexing policies for search engines via the `robots` property:
|
2020-07-27 14:44:47 +02:00
|
|
|
|
|
|
|
|
|
``` html
|
2021-09-12 10:15:21 +02:00
|
|
|
|
{% extends "base.html" %}
|
|
|
|
|
|
2020-07-27 14:44:47 +02:00
|
|
|
|
{% block extrahead %}
|
2023-03-22 18:48:27 +01:00
|
|
|
|
<meta name="robots" content="noindex, nofollow" />
|
2020-07-27 14:44:47 +02:00
|
|
|
|
{% endblock %}
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-10 21:04:22 +02:00
|
|
|
|
[overriding blocks]: ../customization.md#overriding-blocks
|
2021-05-01 19:04:44 +02:00
|
|
|
|
|
2022-12-20 21:21:19 +01:00
|
|
|
|
#### :material-check: on a single page
|
2021-05-01 19:04:44 +02:00
|
|
|
|
|
|
|
|
|
If you want to set a `meta` tag on a single page, or want to set different
|
|
|
|
|
values for different pages, you can use the `page.meta` object inside your
|
|
|
|
|
template override, e.g.:
|
|
|
|
|
|
|
|
|
|
``` html
|
2021-09-12 10:15:21 +02:00
|
|
|
|
{% extends "base.html" %}
|
|
|
|
|
|
2021-05-01 19:04:44 +02:00
|
|
|
|
{% block extrahead %}
|
|
|
|
|
{% if page and page.meta and page.meta.robots %}
|
2023-03-22 18:48:27 +01:00
|
|
|
|
<meta name="robots" content="{{ page.meta.robots }}" />
|
2021-05-01 19:04:44 +02:00
|
|
|
|
{% else %}
|
2023-03-22 18:48:27 +01:00
|
|
|
|
<meta name="robots" content="index, follow" />
|
2021-05-01 19:04:44 +02:00
|
|
|
|
{% endif %}
|
|
|
|
|
{% endblock %}
|
|
|
|
|
```
|
|
|
|
|
|
2021-10-10 13:17:39 +02:00
|
|
|
|
You can now use `robots` exactly like [`title`][title] and
|
|
|
|
|
[`description`][description] to set values. Note that in this case, the
|
|
|
|
|
template defines an `else` branch, which would set a default if none was given.
|
|
|
|
|
|
|
|
|
|
[title]: #setting-the-page-title
|
|
|
|
|
[description]: #setting-the-page-description
|