Giter Site home page Giter Site logo

prcr / mkdocs-meta-descriptions-plugin Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 3.0 4.61 MB

๐Ÿ“‘ Generate meta descriptions from the first paragraphs in your MkDocs pages

Home Page: https://pypi.org/project/mkdocs-meta-descriptions-plugin/

License: MIT License

Python 100.00%
mkdocs meta-description seo paragraph

mkdocs-meta-descriptions-plugin's Introduction

mkdocs-meta-descriptions-plugin

CI/CD Codacy Codacy Badge PyPI

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

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.

  2. Tries to find the first paragraph above any <h2> to <h6> 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 as a fallback.

Setting up and using the plugin

โš ๏ธ Important: to use this plugin, you must either customize your existing theme to include the value of page.meta.description in the HTML element <meta name="description" content="...">, or use an MkDocs theme that already does this by default. I recommend using the excellent Material theme.

To set up and use the plugin:

  1. Install the plugin using pip:

    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:

    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:

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 <site_dir>/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.

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.

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.

See also

Read more about using MkDocs plugins.

mkdocs-meta-descriptions-plugin's People

Contributors

dependabot[bot] avatar prcr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mkdocs-meta-descriptions-plugin's Issues

Incorrect use of <p> text inside <div> as the meta description

Describe the bug
A clear and concise description of what the bug is.

The plugin incorrectly considers the paragraph that contains the title of the admonition as the meta description for a page:

<h1 id="title">Title</h1>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Note text</p>
</div>
<p>This should be used as the meta description</p>

To Reproduce
The list of steps to reproduce the behavior.

Expected behavior
A clear and concise description of what you expected to happen.

The plugin should only consider for the meta description paragraphs that are siblings to the <h1> tag. Decide if in these cases the <div> can be ignored and the next <p> is used, or if no meta description should be deduced from the page content.

Additional context
Add any other context about the problem here.

I identified the issue on this page.

Trim first paragraph text

Trim the text of the first paragraph found, and check the length of the text only after trimming.

Improve detection of the first paragraph when text of first <p> is empty

There are some situations where the text of the first paragraph that is found by the plugin may be empty.

For example:

<p><a href="...">Welcome to the site!</a></p>
<p><img src="..."/></p>

Perhaps in situations like this the plugin could try to find a sibling paragraph that does include text.

Solve deprecation warning for collections.abc

Solve the deprecation warning for collections.abc:

$ mkdocs build
INFO     -  DeprecationWarning: Using or importing the ABCs from 'collections' instead of from
            'collections.abc' is deprecated since Python 3.3, and in 3.10 it will stop working
              File "/usr/lib/python3/dist-packages/html5lib/_trie/_base.py", line 3, in <module>
                from collections import Mapping
              File "/usr/lib/python3.8/collections/__init__.py", line 49, in __getattr__
                warnings.warn("Using or importing the ABCs from 'collections' instead "
INFO     -  Cleaning site directory

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.