From 2f362eaf0937360a0f2a81bac41be81111fa06a8 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Fri, 6 Sep 2024 08:21:27 +0000 Subject: Added reading time timer --- src/plugins/remarkReadingTime.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 src/plugins/remarkReadingTime.ts (limited to 'src/plugins/remarkReadingTime.ts') diff --git a/src/plugins/remarkReadingTime.ts b/src/plugins/remarkReadingTime.ts new file mode 100644 index 0000000..93f7b00 --- /dev/null +++ b/src/plugins/remarkReadingTime.ts @@ -0,0 +1,11 @@ +import type { RemarkPlugin } from "@astrojs/markdown-remark"; +import { toString } from "mdast-util-to-string"; +import getReadingTime from "reading-time"; + +export function remarkReadingTime(): RemarkPlugin { + return function (tree, { data }) { + const textOnPage = toString(tree); + const readingTime = getReadingTime(textOnPage); + data.astro.frontmatter.minutesRead = readingTime.text; + }; +} -- cgit v1.2.3