Fork of Chiri for Astro for my blog
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at a1e6ead60fb44c152fefa3a86179bcf2b84d6249 21 lines 656 B view raw
1import { toString } from 'mdast-util-to-string' 2import getReadingTime from 'reading-time' 3 4/** 5 * Remark plugin to calculate and add reading time information to markdown frontmatter 6 */ 7export default function remarkReadingTime() { 8 return function (tree, file) { 9 const textOnPage = toString(tree) 10 const readingTime = getReadingTime(textOnPage) 11 12 const minutes = Math.max(1, Math.round(readingTime.minutes)) 13 file.data.astro.frontmatter.minutesRead = `${minutes}min` 14 file.data.astro.frontmatter.readingTime = { 15 text: `${minutes}min`, 16 minutes: minutes, 17 time: readingTime.time, 18 words: readingTime.words 19 } 20 } 21}