Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@jcayzac/astro-rehype-frontmatter-reading-stats
Advanced tools
Adds reading time and word count to the frontmatter of markdown/mdx files.
@jcayzac/astro-rehype-frontmatter-reading-stats
Word count and estimated reading time for Astro Markdown/MDX content.
Rehype plugin to add the word count and estimated reading time to the frontmatter of Markdown documents loaded by Astro.
# pnpm
pnpm add @jcayzac/astro-rehype-frontmatter-reading-stats
# bun
bunx add @jcayzac/astro-rehype-frontmatter-reading-stats
# npm
npx add @jcayzac/astro-rehype-frontmatter-reading-stats
# yarn
yarn add @jcayzac/astro-rehype-frontmatter-reading-stats
# deno
deno add npm:@jcayzac/astro-rehype-frontmatter-reading-stats
Add the plugin to your Astro project's astro.config.mjs
:
import { defineConfig } from 'astro/config'
import readingStats from '@jcayzac/astro-rehype-frontmatter-reading-stats'
export default defineConfig({
markdown: {
rehypePlugins: [
readingStats(),
]
}
})
The frontmatter of your Markdown documents will have new fields added:
wordCount
: the approximate number of words in the document.
readingTime
: the estimated reading time in minutes, rounded.
[!TIP] if you want an ISO-8601 duration, for example to use in a
<time>
HTML element, simply use`PT${Math.round(readingTime)}M`
.
You can access those in your Astro components:
---
import type { FrontmatterReadingStats } from '@jcayzac/astro-rehype-frontmatter-reading-stats'
import type { CollectionEntry } from 'astro:content'
interface Props {
article: CollectionEntry<'articles'>
}
const { article } = props as Props
const { Content, remarkPluginFrontmatter } = await article.render()
const { wordCount, readingTime } = remarkPluginFrontmatter as FrontmatterReadingStats
---
<div>
<h1>{article.title}</h1>
<p>{wordCount} words</p>
<time datetime={`PT${Math.round(readingTime)}M`}>A {readingTime}min read</time>
<Content />
</div>
If you like anything here, consider buying me a coffee using one of the following platforms:
FAQs
Adds reading time and word count to the frontmatter of markdown/mdx files.
The npm package @jcayzac/astro-rehype-frontmatter-reading-stats receives a total of 14 weekly downloads. As such, @jcayzac/astro-rehype-frontmatter-reading-stats popularity was classified as not popular.
We found that @jcayzac/astro-rehype-frontmatter-reading-stats demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.