npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@mylesb/astro-remark-first-paragraph-plugin

v1.0.2

Published

Plugin for Remark to get the first paragraph of a markdown file.

Readme

@myles/astro-remark-first-paragraph-plugin

A remark plugin for Astro that copies the text of a markdown file's first paragraph into its frontmatter as firstParagraph.

Useful for generating a description or excerpt for a blog post without having to write one by hand for every file.

Install

npm install @myles/astro-remark-first-paragraph-plugin

Usage

Add the plugin to the markdown.remarkPlugins array in your Astro config:

// astro.config.mjs
import { defineConfig } from "astro/config";
import remarkFirstParagraphPlugin from "@myles/astro-remark-first-paragraph-plugin";

export default defineConfig({
  markdown: {
    remarkPlugins: [remarkFirstParagraphPlugin],
  },
});

Given a markdown file like this:

---
title: Hello, world
---

This is the **first** paragraph, and it has a [link](https://example.com).

This is the second paragraph.

firstParagraph is added to the frontmatter with all inline markup flattened to plain text:

This is the first paragraph, and it has a link.

Read it from frontmatter wherever Astro exposes it — a content collection entry, Astro.props, or import.meta.glob:

---
// src/pages/blog/[...slug].astro
const { frontmatter } = Astro.props;
---

<meta name="description" content={frontmatter.firstParagraph} />

How it works

The plugin looks for the first top-level paragraph node in the mdast tree and recursively joins the value of every descendant node into a single string. Because it only reads text values, formatting such as emphasis, links, and inline code is stripped — you get the words, not the markup. A hard line break becomes a single space; raw inline HTML tags are dropped while the text they wrap is kept; nodes with no text of their own, such as images, contribute nothing.

Only top-level paragraphs count, so a file that opens with a heading, list, blockquote, or table falls through to the first paragraph of real body text:

> A pull quote that opens the post.

This is the paragraph you actually want.
This is the paragraph you actually want.

If a file has no top-level paragraph at all, firstParagraph is left unset, so give it a fallback where you use it:

<meta name="description" content={frontmatter.firstParagraph ?? site.description} />

The result is written to file.data.astro.frontmatter, which is an Astro-specific part of the vfile. That means this plugin works as an Astro remark plugin only; in any other unified/remark pipeline it does nothing.

Development

npm install
npm test                # run the test suite
npm run prettier        # check formatting
npm run prettier:write  # fix formatting

Credits

The original approach comes from Hunor Marton Borbely's post, Add a description to your Astro blog posts automatically.

License

MIT