diff options
Diffstat (limited to 'src/components/ReadingTime.astro')
-rw-r--r-- | src/components/ReadingTime.astro | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/components/ReadingTime.astro b/src/components/ReadingTime.astro new file mode 100644 index 0000000..2c8c676 --- /dev/null +++ b/src/components/ReadingTime.astro @@ -0,0 +1,26 @@ +--- +import type { CollectionEntry } from "astro:content"; +import { default as readingTime } from "reading-time"; + +type Props = { + body: CollectionEntry<"blog">["body"]; + lang: CollectionEntry<"blog">["data"]["lang"]; +}; + +const { body, lang } = Astro.props; + +const reading = readingTime(body ?? "", {}); +const minutes = Math.ceil(reading.minutes); +const estimative = new Intl.DurationFormat(lang, { + style: "long", +}).format({ minutes }); +const duration = `PT${ + Math.floor(minutes / 60) > 0 ? Math.floor(minutes / 60) + "H" : "" +}${minutes % 60 > 0 ? minutes % 60 + "M" : ""}`; +--- +<p> + <data itemprop="timeRequired" value={duration}><bdi>Tempo de leitura + estimado</bdi>: ~ {estimative}</data> + <data itemprop="wordCount" value={reading.words} + >(<bdi>palavras</bdi>: {reading.words})</data> +</p> |