Automatically generate meta description for VuePress 2 pages from your Markdown content.
- Auto-generate meta description from first paragraph(s)
- Paragraph-safe trimming to a configurable maximum length
npm install @dv0vd/vuepress-auto-description- Check existing description: If
page.frontmatter.descriptionis already set, the plugin does nothing and preserves the existing description. - Extract paragraphs: The plugin parses the rendered HTML (
page.contentRendered) and extracts all<p>elements. - Plain text: HTML tags are removed, and whitespace is normalized. Empty paragraphs are ignored.
- Trim to max length:
- The plugin does not cut text in the middle of a word.
- Paragraphs are added sequentially until the total length reaches
maxDescriptionLength. - Because whole paragraphs are added, the final length may slightly exceed the limit to avoid cutting words in half.
- Save description: The final text is assigned to
page.frontmatter.description.
import autoDescriptionPlugin from '@dv0vd/vuepress-auto-description';
export default {
plugins: [
autoDescriptionPlugin(160),
],
};| Option | Type | Default | Description |
|---|---|---|---|
maxDescriptionLength |
number | 150 | Maximum number of characters for the description |