e2019be6ff
* feat: make user frontmatter accessible in md * test: new frontmatter injection * refactor: move injection utils to remark pkg * fix: add dist/internal to remark exports * feat: update frontmater injection in mdx * tests: new mdx injection * chore: changeset * chore: simplify frontmatter destructuring * fix: remove old _internal references * refactor: injectedFrontmatter -> remarkPluginFrontmatter * docs: add content collections change * chore: changeset heading levels
27 lines
759 B
JavaScript
27 lines
759 B
JavaScript
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}`
|
|
};
|
|
}
|