2020-03-09 19:03:48 +01:00
|
|
|
---
|
|
|
|
hero: Set heroes with metadata
|
2017-03-11 16:15:23 +01:00
|
|
|
path: tree/master/docs/extensions
|
|
|
|
source: metadata.md
|
2020-03-09 19:03:48 +01:00
|
|
|
---
|
2017-03-11 16:15:23 +01:00
|
|
|
|
|
|
|
# Metadata
|
|
|
|
|
2020-03-09 23:12:10 +01:00
|
|
|
[Metadata][1] is an extension included in the standard Markdown library that
|
|
|
|
makes it possible to control certain properties in a page-specific context,
|
|
|
|
e.g. the page title or description.
|
2017-03-11 16:15:23 +01:00
|
|
|
|
2018-02-22 19:26:35 +01:00
|
|
|
[1]: https://python-markdown.github.io/extensions/meta_data/
|
2017-03-11 16:15:23 +01:00
|
|
|
|
2020-03-09 19:03:48 +01:00
|
|
|
## Configuration
|
2017-03-11 16:15:23 +01:00
|
|
|
|
2020-03-09 19:03:48 +01:00
|
|
|
Add the following lines to `mkdocs.yml`:
|
2017-03-11 16:15:23 +01:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
markdown_extensions:
|
2017-03-11 17:24:03 +01:00
|
|
|
- meta
|
2017-03-11 16:15:23 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
Metadata is written as a series of key-value pairs at the beginning of the
|
|
|
|
Markdown document, delimited by a blank line which ends the metadata context.
|
|
|
|
Naturally, the metadata is stripped from the document before rendering the
|
|
|
|
actual page content and made available to the theme.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
``` markdown
|
2020-03-09 19:03:48 +01:00
|
|
|
---
|
2017-03-11 16:15:23 +01:00
|
|
|
title: Lorem ipsum dolor sit amet
|
|
|
|
description: Nullam urna elit, malesuada eget finibus ut, ac tortor.
|
2017-03-11 18:36:34 +01:00
|
|
|
path: path/to/file
|
2017-03-11 16:15:23 +01:00
|
|
|
source: file.js
|
2020-03-09 19:03:48 +01:00
|
|
|
---
|
2017-03-11 16:15:23 +01:00
|
|
|
|
|
|
|
# Headline
|
|
|
|
|
|
|
|
...
|
|
|
|
```
|
|
|
|
|
2020-03-20 16:47:47 +01:00
|
|
|
See the next section which covers the supported metadata.
|
2017-03-11 16:15:23 +01:00
|
|
|
|
2020-03-09 19:03:48 +01:00
|
|
|
### Setting a hero
|
2017-11-22 00:13:56 +01:00
|
|
|
|
2020-03-20 16:47:47 +01:00
|
|
|
Material for MkDocs exposes a simple text-only page-local hero via Metadata, as
|
|
|
|
you can see on the current page when you scroll to the top. It's as simple as:
|
2017-11-22 00:13:56 +01:00
|
|
|
|
|
|
|
``` markdown
|
2020-03-09 19:03:48 +01:00
|
|
|
hero: Set heroes with metadata
|
2017-11-22 00:13:56 +01:00
|
|
|
```
|
|
|
|
|
2018-02-11 19:18:33 +01:00
|
|
|
### Linking sources
|
|
|
|
|
2020-02-24 18:07:50 +01:00
|
|
|
When a document is related to a specific source file and the `repo_url` is
|
|
|
|
defined inside the project's `mkdocs.yml`, the file can be linked using the
|
2018-02-11 19:18:33 +01:00
|
|
|
`source` key:
|
|
|
|
|
|
|
|
``` markdown
|
|
|
|
source: file.js
|
|
|
|
```
|
|
|
|
|
2020-03-09 19:03:48 +01:00
|
|
|
The filename is appended to the `repo_url` set in `mkdocs.yml`, but can be
|
|
|
|
prefixed with a `path` to ensure correct path resolving. The name of the source
|
|
|
|
file is shown in the tooltip.
|
2018-02-11 19:18:33 +01:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
``` markdown
|
|
|
|
path: tree/master/docs/extensions
|
|
|
|
source: metadata.md
|
|
|
|
```
|
|
|
|
|
2018-12-28 15:11:54 +01:00
|
|
|
### Redirecting to another page
|
|
|
|
|
|
|
|
It's sometimes necessary to move documents around in the navigation tree and
|
2020-03-20 16:47:47 +01:00
|
|
|
redirect users from the old URL to the new one. The `redirect` meta-tag allows
|
2018-12-28 15:11:54 +01:00
|
|
|
to create a redirection from the current document to the address specified in
|
|
|
|
the tag.
|
|
|
|
|
|
|
|
For instance, if your document contains:
|
|
|
|
|
|
|
|
``` markdown
|
|
|
|
redirect: /new/url
|
|
|
|
```
|
|
|
|
|
|
|
|
accessing that document's URL will automatically redirect to `/new/url`.
|
|
|
|
|
2018-02-11 19:18:33 +01:00
|
|
|
### Overrides
|
|
|
|
|
|
|
|
#### Page title
|
2017-03-11 16:15:23 +01:00
|
|
|
|
2020-03-09 19:03:48 +01:00
|
|
|
The page title can be overridden on a per-document basis:
|
2017-03-11 16:15:23 +01:00
|
|
|
|
|
|
|
``` markdown
|
|
|
|
title: Lorem ipsum dolor sit amet
|
|
|
|
```
|
|
|
|
|
|
|
|
This will set the `title` tag inside the document `head` for the current page
|
2017-03-11 18:36:34 +01:00
|
|
|
to the provided value. It will also override the default behavior of Material
|
2017-03-11 16:15:23 +01:00
|
|
|
for MkDocs which appends the site title using a dash as a separator to the page
|
|
|
|
title.
|
|
|
|
|
2018-02-11 19:18:33 +01:00
|
|
|
#### Page description
|
2017-03-11 16:15:23 +01:00
|
|
|
|
2020-03-09 19:03:48 +01:00
|
|
|
The page description can also be overridden on a per-document basis:
|
2017-03-11 16:15:23 +01:00
|
|
|
|
|
|
|
``` yaml
|
|
|
|
description: Nullam urna elit, malesuada eget finibus ut, ac tortor.
|
|
|
|
```
|
|
|
|
|
|
|
|
This will set the `meta` tag containing the site description inside the
|
|
|
|
document `head` for the current page to the provided value.
|
|
|
|
|
2018-02-11 19:18:33 +01:00
|
|
|
#### Disqus
|
2017-03-11 16:15:23 +01:00
|
|
|
|
2020-03-09 19:03:48 +01:00
|
|
|
As described in the [getting started guide][3], Disqus can be enabled on a
|
|
|
|
per-document basis:
|
2017-03-11 16:15:23 +01:00
|
|
|
|
|
|
|
``` markdown
|
2018-02-11 19:18:33 +01:00
|
|
|
disqus: your-shortname
|
2017-03-11 16:15:23 +01:00
|
|
|
```
|
|
|
|
|
2020-03-09 19:03:48 +01:00
|
|
|
Disqus can also be disabled for a specific page by setting it to an empty value:
|
2017-03-11 16:15:23 +01:00
|
|
|
|
|
|
|
``` markdown
|
2018-02-11 19:18:33 +01:00
|
|
|
disqus:
|
2017-03-11 16:15:23 +01:00
|
|
|
```
|
|
|
|
|
2018-02-11 19:18:33 +01:00
|
|
|
[3]: ../getting-started.md#disqus
|