astro/packages/integrations/mdx/test/fixtures/mdx-frontmatter-injection/src/markdown-plugins.mjs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

21 lines
541 B
JavaScript
Raw Normal View History

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);
}
});
};
}