@@ -6,57 +6,60 @@ template: overrides/main.html
6
6
7
7
In HTML, ` meta ` tags allow to provide additional metadata for a document, e.g.
8
8
page titles and descriptions, additional assets to be loaded, and [ Open Graph]
9
- [ 1 ] data . While arbitrary metadata can always be added via [ customization] [ 2 ] ,
9
+ metadata . While arbitrary ` meta ` tags can always be added via [ customization] ,
10
10
some common ` meta ` tags can be configured.
11
11
12
- [ 1 ] : https://ogp.me/
13
- [ 2 ] : #customization
12
+ [ Open Graph ] : https://ogp.me/
13
+ [ customization ] : #customization
14
14
15
15
## Configuration
16
16
17
- ### Metadata
18
-
19
- The [ Metadata] [ 3 ] extension, which is part of the standard Markdown library,
20
- adds the ability to add [ front matter] [ 4 ] to a document and can be enabled via
21
- ` mkdocs.yml ` :
17
+ This configuration adds support for setting custom page titles and descriptions
18
+ in [ front matter] , as well as for using custom metadata in templates. Add the
19
+ following lines to ` mkdocs.yml ` :
22
20
23
21
``` yaml
24
22
markdown_extensions :
25
23
- meta
26
24
` ` `
27
25
28
- Front matter is written as a series of key-value pairs at the beginning of the
29
- Markdown document, delimited by a blank line which ends the YAML context.
26
+ See additional configuration options:
27
+
28
+ - [Metadata]
30
29
31
- [3 ]: https://python-markdown.github.io/extensions/meta_data /
32
- [4 ]: https://jekyllrb.com/docs/front-matter/
30
+ [front matter ]: https://jekyllrb.com/docs/front-matter /
31
+ [Metadata ]: ../setup/extensions/python-markdown.md#metadata
33
32
34
33
## Usage
35
34
36
35
### Setting the page title
37
36
38
- If the [Metadata][5] extension is enabled, the page title can be overridden on
39
- a per-document basis with custom front matter:
37
+ When [Metadata] is enabled, the page title can be overridden on a per-document
38
+ basis with custom front matter. Add the following lines at the top of a Markdown
39
+ file:
40
40
41
41
` ` ` bash
42
42
---
43
- title : Lorem ipsum dolor sit amet
43
+ title : Lorem ipsum dolor sit amet # (1)
44
44
---
45
45
46
46
# Document title
47
47
...
48
48
```
49
49
50
- This will set the ` title ` tag inside the document ` head ` for the current page
51
- to the provided value. Note that the site title is appended using a dash as a
52
- separator, which is the default behavior .
50
+ 1 . This will set the [ ` title ` ] [ title ] inside the HTML document's [ ` head ` ] [ head ]
51
+ for the generated page to this value. Note that the site title, which is set
52
+ via [ ` site_name ` ] [ site_name ] , is appended with a dash .
53
53
54
- [ 5 ] : #metadata
54
+ [ title ] : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title
55
+ [ head ] : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/head
56
+ [ site_name ] : https://www.mkdocs.org/user-guide/configuration/#site_name
55
57
56
58
### Setting the page description
57
59
58
- If the [ Metadata] [ 5 ] extension is enabled, the page description can also be
59
- overridden on a per-document basis with custom front matter:
60
+ When [ Metadata] is enabled, the page description can also be overridden on a
61
+ per-document basis with custom front matter. Add the following lines at the top
62
+ of a Markdown file:
60
63
61
64
``` bash
62
65
---
@@ -70,47 +73,41 @@ description: Nullam urna elit, malesuada eget finibus ut, ac tortor.
70
73
This will set the ` meta ` tag containing the site description inside the
71
74
document ` head ` for the current page to the provided value.
72
75
76
+ <div class =" mdx-deprecated " markdown >
77
+
73
78
### Adding a web app manifest
74
79
75
- A [ web app manifest] [ 6 ] is a simple JSON file that specifies how your web
80
+ :octicons-archive-24: Deprecated ·
81
+ [ :octicons-tag-24: 3.1.0 ... present] [ web app manifest support ] ·
82
+ :octicons-trash-24: 8.0.0
83
+
84
+ A [ web app manifest] is a simple JSON file that specifies how your web
76
85
application should behave when installed on the user's mobile device or desktop,
77
86
which can be set via ` mkdocs.yml ` :
78
87
79
88
``` yaml
80
89
extra :
81
- manifest : manifest.webmanifest
90
+ manifest : manifest.webmanifest # (1)
82
91
` ` `
83
92
84
- [6]: https://developers.google.com/web/fundamentals/web-app-manifest/
93
+ 1. This option was deprecated, as it's not widely used and the same behavior
94
+ can be achieved with [theme extension].
85
95
86
- ## Customization
87
-
88
- ### Displaying the metadata
96
+ [web app manifest]: https://developers.google.com/web/fundamentals/web-app-manifest/
97
+ [web app manifest support]: https://github.com/squidfunk/mkdocs-material/releases/tag/3.1.0
98
+ [theme extension]: ../customization.md#extending-the-theme
89
99
90
- Sometimes it's useful to be able to display the medatada in the page body, e.g.
91
- print the name of the page author at the bottom of the page. To achieve that,
92
- you can [extend the theme][7] by adding the following contents to ` main.html`:
100
+ </div>
93
101
94
- ` ` ` html
95
- {% extends "base.html" %}
96
-
97
- {% block content %}
98
- {{ super() }}
99
- {% if page and page.meta and page.meta.author %}
100
- <p><small>Author: {{ page.meta.author }}</small></p>
101
- {% endif %}
102
- {% endblock %}
103
- ` ` `
104
-
105
- [7] : ../customization.md#extending-the-theme
102
+ ## Customization
106
103
107
- # ## Custom meta tags
104
+ ### Using metadata in templates
108
105
109
106
#### on all pages
110
107
111
108
In order to add custom ` meta` tags to your document, you can [extend the theme
112
- ][7 ] and simply [override the `extrahead` block][8], e.g. to add indexing
113
- policies for search engines :
109
+ ][theme extension ] and [override the `extrahead` block][override block],
110
+ e.g. to add indexing policies for search engines via the `robots` property :
114
111
115
112
` ` ` html
116
113
{% extends "base.html" %}
@@ -120,7 +117,7 @@ policies for search engines:
120
117
{% endblock %}
121
118
` ` `
122
119
123
- [8 ] : ../customization.md#overriding-blocks-recommended
120
+ [override block ] : ../customization.md#overriding-blocks-recommended
124
121
125
122
# ### on a single page
126
123
@@ -140,63 +137,9 @@ template override, e.g.:
140
137
{% endblock %}
141
138
` ` `
142
139
143
- You can now use `robots` exactly like [`title`][9] and [`description`][10] to
144
- set values. Note that in this case, the template defines an `else` branch, which
145
- would set a default if none was given.
146
-
147
- [9] : # setting-the-page-title
148
- [10] : # setting-the-page-description
149
-
150
- # ## Social meta tags
151
-
152
- Some further examples, including [Open Graph][1] and [Twitter Cards][11] :
153
-
154
- === "Open Graph"
155
-
156
- ` ` ` html
157
- {% block extrahead %}
158
- {% set title = config.site_name %}
159
- {% if page and page.meta and page.meta.title %}
160
- {% set title = title ~ " - " ~ page.meta.title %}
161
- {% elif page and page.title and not page.is_homepage %}
162
- {% set title = title ~ " - " ~ page.title | striptags %}
163
- {% endif %}
164
- <meta property="og:type" content="website" />
165
- <meta property="og:title" content="{{ title }}" />
166
- <meta property="og:description" content="{{ config.site_description }}" />
167
- <meta property="og:url" content="{{ page.canonical_url }}" />
168
- <meta property="og:image" content="<url>" />
169
- <meta property="og:image:type" content="image/png" />
170
- <meta property="og:image:width" content="1200" />
171
- <meta property="og:image:height" content="630" />
172
- {% endblock %}
173
- ` ` `
174
-
175
- === "Twitter Cards"
176
-
177
- ` ` ` html
178
- {% block extrahead %}
179
- {% set title = config.site_name %}
180
- {% if page and page.meta and page.meta.title %}
181
- {% set title = title ~ " - " ~ page.meta.title %}
182
- {% elif page and page.title and not page.is_homepage %}
183
- {% set title = title ~ " - " ~ page.title | striptags %}
184
- {% endif %}
185
- <meta name="twitter:card" content="summary_large_image" />
186
- <meta name="twitter:site" content="<username>" />
187
- <meta name="twitter:creator" content="<username>" />
188
- <meta name="twitter:title" content="{{ title }}" />
189
- <meta name="twitter:description" content="{{ config.site_description }}" />
190
- <meta name="twitter:image" content="<url>" />
191
- {% endblock %}
192
- ` ` `
193
-
194
- !!! tip "Automatically generated social cards"
195
-
196
- If you don't want to bother with meta tags and social cards yourself, you
197
- can let the [built-in social cards plugin][12] do the work for you, which
198
- generates beautiful image previews for social media automatically during
199
- the build.
200
-
201
- [11] : https://developer.twitter.com/en/docs/tweets/optimize-with-cards/overview/abouts-cards
202
- [12] : ../setup/setting-up-social-cards.md
140
+ You can now use `robots` exactly like [`title`][title] and
141
+ [`description`][description] to set values. Note that in this case, the
142
+ template defines an `else` branch, which would set a default if none was given.
143
+
144
+ [title] : # setting-the-page-title
145
+ [description] : # setting-the-page-description
0 commit comments