16 lines
476 B
JavaScript
16 lines
476 B
JavaScript
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;
|
|
};
|
|
}
|