@dv0vd/vuepress-auto-description
v1.0.3
Published
VuePress 2 Meta Description Generator
Maintainers
Readme
@dv0vd/vuepress-auto-description
Automatically generate meta description for VuePress 2 pages from your Markdown content.
Features
- Auto-generate meta description from first paragraph(s)
- Paragraph-safe trimming to a configurable maximum length
Installation
npm install @dv0vd/vuepress-auto-descriptionHow It Works
- 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.
Usage
import autoDescriptionPlugin from '@dv0vd/vuepress-auto-description';
export default {
plugins: [
autoDescriptionPlugin(160),
],
};Options
| Option | Type | Default | Description |
| ------------------------- | ------ | ------- | ----------------------------------------------------------------------------------------------------- |
| maxDescriptionLength | number | 150 | Maximum number of characters for the description |
