blob: 35b415787a45af7e83fd92c506ea1ec971a29dfb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
import getReadingTime from 'reading-time';
import { toString } from 'mdast-util-to-string';
import { visit } from 'unist-util-visit';
export function rehypeReadingTime() {
return function (tree, { data }) {
const readingTime = getReadingTime(toString(tree));
data.astro.frontmatter.injectedReadingTime = readingTime;
};
}
export function remarkTitle() {
return function (tree, { data }) {
visit(tree, ['heading'], (node) => {
if (node.depth === 1) {
data.astro.frontmatter.title = toString(node.children);
}
});
};
}
export function remarkDescription() {
return function (tree, vfile) {
const { frontmatter } = vfile.data.astro;
frontmatter.description = `Processed by remarkDescription plugin: ${frontmatter.description}`
};
}
|