Custom plugin for description and "minutes reading"

This commit is contained in:
DarkCat09 2023-06-18 20:00:53 +04:00
parent 82d3214187
commit 94f3de5337
5 changed files with 236 additions and 8 deletions

16
remark-post-meta.mjs Normal file
View 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;
};
}