An MkDocs plugin to customize the first paragraph of your pages, and to use it as the page's meta description.
This is useful if the first paragraph of your pages
- contains information that should stand out from the rest of the text, e.g., should be printed in bold ("teaser" text)
- should appear as the page description in search engines (for SEO).
Install the package with pip:
pip install mkdocs-add-teaser
Enable the plugin in your mkdocs.yml:
plugins:
- search
- mkdocs-add-teaser:
teaser_class: 'teaser'
add_to_meta: trueNote: If you have no
pluginsentry in your config file yet, you'll likely also want to add thesearchplugin. MkDocs enables it by default if there is nopluginsentry set, but now you have to enable it explicitly.
Add the CSS class to your extra CSS file. See examples below.
.teaser {
font-weight: bold;
}.teaser {
font-size: 120%;
}.teaser {
color: darkgray;
}.teaser {
font-weight: bold;
font-size: 120%;
color: darkgray;
}The following options are provided to configure the output:
add_to_meta: If set totrueand your page doesn't contain a meta description, the teaser text will be used as the meta description. Defaults tofalse.teaser_class: The CSS class to be applied to the first paragraph of your pages. Defaults toteaser.
The teaser plugin can be disabled on specific pages using the front matter hide property. The teaser text will still be shown, but no CSS class will be applied, and the meta description won't be changed.
Add the following lines at the top of a Markdown file:
---
hide:
- teaser
---
# Document Title
...This is the HTML that Markdown will produce:
<h1 id="...">...</h1>
<p>First paragraph</p>This is the HTML after this plugin has run:
With add_to_meta set to false (default):
<h1 id="...">...</h1>
<p class="teaser">First paragraph</p>With add_to_meta set to true:
<meta content="description" content="First paragraph">
...
<h1 id="...">...</h1>
<p class="teaser">First paragraph</p>