1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2024-12-20 03:16:06 +01:00
mkdocs-material/docs/reference/index.md

166 lines
4.6 KiB
Markdown
Raw Normal View History

---
template: overrides/main.html
---
2021-12-16 17:08:57 +01:00
# Reference
2021-12-16 17:08:57 +01:00
Material for MkDocs is packed with many great features that make technical
writing a pleasure. This section of the documentation explains how to set up
a page, and showcases all available specimen that can be used directly from
within Markdown files.
## Configuration
2021-12-16 17:08:57 +01:00
This configuration allows to set a title and description for a page, change the
template or define an icon to be rendered in the navigation. Add the following
lines to `mkdocs.yml`:
``` yaml
markdown_extensions:
- meta
```
See additional configuration options:
- [Metadata]
2020-07-22 19:11:22 +02:00
[front matter]: https://jekyllrb.com/docs/front-matter/
[Metadata]: ../setup/extensions/python-markdown.md#metadata
2020-07-22 19:11:22 +02:00
2020-07-27 13:50:31 +02:00
## Usage
2020-07-22 19:11:22 +02:00
### Setting the page title
2020-07-22 19:11:22 +02:00
2021-10-10 17:39:53 +02:00
When [Metadata] is enabled, the page title can be overridden for a document with
some custom front matter. Add the following lines at the top of a Markdown file:
2020-07-22 19:11:22 +02:00
2021-05-30 15:59:13 +02:00
``` bash
---
2021-12-11 14:30:07 +01:00
title: Lorem ipsum dolor sit amet # (1)!
---
2021-05-30 15:59:13 +02:00
# Document title
...
2020-07-22 19:11:22 +02:00
```
1. This will set the [`title`][title] inside the HTML document's [`head`][head]
for the generated page to this 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
[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
### Setting the page description
2020-07-22 19:11:22 +02:00
2021-10-10 17:39:53 +02:00
When [Metadata] is enabled, the page description can be overridden for a
document with custom front matter. Add the following lines at the top of a
Markdown file:
2020-07-22 19:11:22 +02:00
2021-05-30 15:59:13 +02:00
``` bash
---
2021-12-16 17:08:57 +01:00
description: Nullam urna elit, malesuada eget finibus ut, ac tortor. # (1)!
---
# Document title
...
```
1. This will set the `meta` tag containing the site description inside the
document `head` for the current page to the provided value.
### Setting the page icon
[:octicons-heart-fill-24:{ .mdx-heart } Insiders][Insiders]{ .mdx-insiders } ·
[:octicons-tag-24: insiders-4.5.0][Insiders] ·
:octicons-beaker-24: Experimental
An icon can be assigned to each page, which is then rendered as part of the
navigation sidebar. Ensure [Metadata] is enabled and add the following lines
at the top of a Markdown file:
``` bash
---
icon: material/emoticon-happy # (1)!
---
2021-05-30 15:59:13 +02:00
# Document title
...
2020-07-22 19:11:22 +02: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
### Setting the page template
If you're using [theme extension] and created a new page template in the
`overrides` directory, you can enable it for a specific page. Add the following
lines at the top of a Markdown file:
``` bash
---
template: custom.html
---
# Document title
...
```
[theme extension]: ../customization.md#extending-the-theme
2020-07-27 13:50:31 +02:00
## Customization
### Using metadata in templates
2020-09-20 11:24:46 +02:00
2021-05-01 19:04:44 +02:00
#### on all pages
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],
e.g. to add indexing policies for search engines via the `robots` property:
``` html
{% extends "base.html" %}
{% block extrahead %}
2020-08-10 12:50:37 +02:00
<meta property="robots" content="noindex, nofollow" />
{% endblock %}
```
2021-10-10 21:04:22 +02:00
[overriding blocks]: ../customization.md#overriding-blocks
2021-05-01 19:04:44 +02:00
#### on a single page
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
{% extends "base.html" %}
2021-05-01 19:04:44 +02:00
{% block extrahead %}
{% if page and page.meta and page.meta.robots %}
<meta property="robots" content="{{ page.meta.robots }}" />
{% else %}
<meta property="robots" content="index, follow" />
{% endif %}
{% endblock %}
```
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