Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jcayzac/astro-rehype-frontmatter-reading-stats

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jcayzac/astro-rehype-frontmatter-reading-stats

Adds reading time and word count to the frontmatter of markdown/mdx files.

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
decreased by-35.71%
Maintainers
0
Weekly downloads
 
Created
Source

@jcayzac/astro-rehype-frontmatter-reading-stats

Rehype plugin to add the word count and estimated reading time to the frontmatter of Markdown documents loaded by Astro.

Installation

# 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

Usage

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.

You can access those in your Astro components:

---
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
---
<div>
  <h1>{article.title}</h1>
  <p>{wordCount} words</p>
  <time datetime={`PT${readingTime}M`}>A {readingTime}min read</time>
  <Content />
</div>

Like it? Buy me a coffee!

If you like anything here, consider buying me a coffee using one of the following platforms:

GitHub SponsorsRevolutWiseKo-FiPayPal

Keywords

FAQs

Package last updated on 20 Aug 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc