@plugdash/readtime

readtime

280 words·2min read

What it does

Calculates reading time in minutes from the word count of your post's Portable Text body. Writes two fields to metadata on every publish: readingTimeMinutes (integer, min 1) and wordCount (integer). Ships ReadingTime.astro with four variants.

Install

npm install @plugdash/readtime

Register

Open astro.config.mjs at the root of your Astro project. Import the plugin at the top, then add it to the plugins array of the emdash() integration - the one that sits inside Astro's top-level integrations array:

// astro.config.mjs
import { defineConfig } from "astro/config"
import emdash from "emdash/astro"
import { readtimePlugin } from "@plugdash/readtime"

export default defineConfig({
  integrations: [
    emdash({
      plugins: [
        readtimePlugin({ collections: ["blog"] }),
      ],
    }),
  ],
})

Add the component

---
import ReadingTime from "@plugdash/readtime/ReadingTime.astro"
---
<ReadingTime post={post} />

Live demo

All four variants, rendered against a fixture post:

5min read 5min read 5min read 5min read

Props

proptypedefaultdescription
postEmDash content itemRequired - the post
variant"badge" | "pill" | "inline" | "minimal""badge"Visual style
size"sm" | "md" | "lg""md"Size scale
labelstring"min read"Text after the number
showWordsbooleanfalseAlso show word count

CSS custom properties

tokendescription
--plugdash-rt-colorText colour
--plugdash-rt-sizeFont size
--plugdash-rt-bgBackground (badge/pill only)
--plugdash-rt-borderBorder colour (badge only)
--plugdash-rt-radiusBorder radius (badge/pill)
--plugdash-rt-paddingPadding (badge/pill)

For agents

After install and registration, verify setup by publishing a test post and checking that post.data.metadata.readingTimeMinutes is populated. If it is not, confirm the post status is "published" and the post's collection appears in the collections option.

built with plugdash