Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prcr/mkdocs-meta-descriptions-plugin
📑 Generate meta descriptions from the first paragraphs in your MkDocs pages
https://github.com/prcr/mkdocs-meta-descriptions-plugin
meta-description mkdocs paragraph seo
Last synced: 5 days ago
JSON representation
📑 Generate meta descriptions from the first paragraphs in your MkDocs pages
- Host: GitHub
- URL: https://github.com/prcr/mkdocs-meta-descriptions-plugin
- Owner: prcr
- License: mit
- Created: 2021-04-02T13:21:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-30T00:21:05.000Z (16 days ago)
- Last Synced: 2024-10-30T02:49:31.620Z (16 days ago)
- Topics: meta-description, mkdocs, paragraph, seo
- Language: Python
- Homepage: https://pypi.org/project/mkdocs-meta-descriptions-plugin/
- Size: 5.23 MB
- Stars: 17
- Watchers: 1
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# mkdocs-meta-descriptions-plugin
[![CI/CD](https://github.com/prcr/mkdocs-meta-descriptions-plugin/actions/workflows/test-build-deploy.yml/badge.svg)](https://github.com/prcr/mkdocs-meta-descriptions-plugin/actions/workflows/test-build-deploy.yml)
[![Codacy](https://app.codacy.com/project/badge/Grade/08bc759a053f475091318f53ea67bd05)](https://app.codacy.com/gh/prcr/mkdocs-meta-descriptions-plugin/dashboard?utm_source=github.com&utm_medium=referral&utm_content=prcr/mkdocs-meta-descriptions-plugin&utm_campaign=Badge_Grade)
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/08bc759a053f475091318f53ea67bd05)](https://app.codacy.com/gh/prcr/mkdocs-meta-descriptions-plugin/dashboard?utm_source=github.com&utm_medium=referral&utm_content=prcr/mkdocs-meta-descriptions-plugin&utm_campaign=Badge_Coverage)
[![PyPI](https://img.shields.io/pypi/dm/mkdocs-meta-descriptions-plugin?label=PyPI)](https://pypi.org/project/mkdocs-meta-descriptions-plugin/)Use this MkDocs plugin to automatically generate meta descriptions for your pages using the first paragraph of each page. This is useful if you start each page with a short introduction or summary that can be reused as the meta description.
![Meta description obtained from first paragraph of the page](https://raw.githubusercontent.com/prcr/mkdocs-meta-descriptions-plugin/main/images/readme-example.png)
For each page, the plugin:
1. Checks that the page doesn't already have a meta description.
The plugin **doesn't change** any meta descriptions defined explicitly on the [page meta-data](https://www.mkdocs.org/user-guide/writing-your-docs/#meta-data).
2. Tries to find the first paragraph above any `
` to `
` headings.
The plugin only searches for the first paragraph until the start of the first section to ensure that the content is from the "introductory" part of the page.
3. Sets the meta description of the page to the plain text context of the paragraph, stripped of HTML tags.
If the page doesn't have a meta description defined manually by you nor automatically by the plugin, MkDocs sets the meta description of the page to the value of your [`site_description`](https://www.mkdocs.org/user-guide/configuration/#site_description) as a fallback.
## Setting up and using the plugin
> ⚠️ **Important:** to use this plugin, you must either [customize your existing theme](https://www.mkdocs.org/user-guide/styling-your-docs/#overriding-template-blocks) to include the value of [`page.meta.description`](https://www.mkdocs.org/user-guide/custom-themes/#pagemeta) in the HTML element ``, or use an [MkDocs theme](https://github.com/mkdocs/mkdocs/wiki/MkDocs-Themes) that already does this by default. I recommend using the excellent [Material theme](https://github.com/squidfunk/mkdocs-material).
To set up and use the plugin:
1. Install the plugin using pip:
```bash
pip install mkdocs-meta-descriptions-plugin
```Depending on your project, you may also need to add the plugin as a dependency on your `requirements.txt` file.
2. Activate the plugin in your `mkdocs.yml`:
```yaml
plugins:
- search
- meta-descriptions
```> **Note:** If you didn't have a `plugins` declaration in your `mkdocs.yml` file before this step, you'll likely also want to add the `search` plugin. This is because MkDocs enables the `search` plugin by default when there is no `plugins` declaration, but now you have to enable it explicitly.
## Configuring the plugin
Use the following options to configure the behavior of the plugin:
```yaml
plugins:
- meta-descriptions:
export_csv: false
quiet: false
enable_checks: false
min_length: 50
max_length: 160
trim: false
```### `export_csv`
If `true`, the plugin exports the meta descriptions of all Markdown pages to the CSV file `/meta-descriptions.csv`. The default is `false`.
This is useful to review and keep track of all the meta descriptions for your pages, especially if you're maintaining a big site.
### `quiet`
If `true`, the plugin logs messages of level `INFO` using the level `DEBUG` instead. The default is `false`.
Enable this option to have a cleaner MkDocs console output. You can still see all logs by running MkDocs with the `--verbose` flag.
### `enable_checks`
If `true`, the plugin outputs a warning for each page that will have an empty or default meta description, as well as for each meta description shorter than `min_length` or longer than `max_length`. The default is `false`.
Enable this option if you want to make sure that all pages have a meta description and that each meta description follows general SEO best practices.
### `min_length`
Minimum number of characters that each meta description should have. The default is 50 characters, based on [these general recommendations](https://moz.com/learn/seo/meta-description).
Make sure that you set `enable_checks: true` for this option to have an effect.
### `max_length`
Maximum number of characters that each meta description should have. The default is 160 characters, based on [these general recommendations](https://moz.com/learn/seo/meta-description).
Make sure that you set `enable_checks: true` or `trim: true` for this option to have an effect.
### `trim`
If `true`, the plugin trims meta descriptions coming from the first paragraph of the pages to include at most `max_length` characters.
Note that this option doesn't change any meta descriptions defined explicitly on the [page meta-data](https://www.mkdocs.org/user-guide/writing-your-docs/#meta-data).
## See also
Read more about [using MkDocs plugins](http://www.mkdocs.org/user-guide/plugins/).