Custom plugin for description and "minutes reading"
This commit is contained in:
parent
82d3214187
commit
94f3de5337
5 changed files with 236 additions and 8 deletions
16
remark-post-meta.mjs
Normal file
16
remark-post-meta.mjs
Normal file
|
@ -0,0 +1,16 @@
|
|||
import getReadingTime from 'reading-time';
|
||||
import { toString as mdToString } from 'mdast-util-to-string';
|
||||
|
||||
const ELLIPSIS = '\u2026';
|
||||
|
||||
export default function() {
|
||||
return function (tree, { data }) {
|
||||
const textOnPage = mdToString(tree);
|
||||
|
||||
const readingTime = getReadingTime(textOnPage);
|
||||
data.astro.frontmatter.readingTime = readingTime.text;
|
||||
|
||||
const description = textOnPage.slice(0, 100) + ELLIPSIS;
|
||||
data.astro.frontmatter.description = description;
|
||||
};
|
||||
}
|
Loading…
Add table
Reference in a new issue