Skip to content

Commit 9201a29

Browse files
committed
fix: render time in frontmatter
1 parent 8c45261 commit 9201a29

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/lib/remark.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import getReadingTime from 'reading-time';
2+
import { toString } from 'mdast-util-to-string';
3+
4+
export function remarkReadingTime() {
5+
return function (tree, { data }) {
6+
const textOnPage = toString(tree);
7+
const readingTime = getReadingTime(textOnPage);
8+
// readingTime.text will give us minutes read as a friendly string,
9+
// i.e. "3 min read"
10+
data.astro.frontmatter.minutesRead = readingTime.text;
11+
};
12+
}

0 commit comments

Comments
 (0)