diff options
author | Valentin Popov <valentin@popov.link> | 2024-09-06 11:21:27 +0300 |
---|---|---|
committer | Valentin Popov <valentin@popov.link> | 2024-09-06 11:21:27 +0300 |
commit | 2f362eaf0937360a0f2a81bac41be81111fa06a8 (patch) | |
tree | c4112b7007de8f2a6dc498b81ab02ab68f126834 /src/plugins/remarkReadingTime.ts | |
parent | 17c3115a0608bb7ef42c8038b36f24b2356004ec (diff) | |
download | popov.link-2f362eaf0937360a0f2a81bac41be81111fa06a8.tar.xz popov.link-2f362eaf0937360a0f2a81bac41be81111fa06a8.zip |
Added reading time timer
Diffstat (limited to 'src/plugins/remarkReadingTime.ts')
-rw-r--r-- | src/plugins/remarkReadingTime.ts | 11 |
1 files changed, 11 insertions, 0 deletions
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; + }; +} |