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

blog-for-next-js

v1.0.3

Published

Make markdown files accessible to Next.js pages.

Readme

README

This project is a work in progress.

blog-for-next-js is a JS library (written in TypeScript) for finding markdown files and making them accessible to Next.js pages.

Take a look at the GitHub repository. The source code is MIT Licensed.

Install

npm install blog-for-next-js

or

yarn add blog-for-next-js

Use

By default, we assume all blog posts (*.md files) are located in the /posts/ directory of your Next.js project.

/pages/blog/index.tsx

Use the following code to extract the slugs for your blog. Your page can then loop through the slugs (string[]) to create links to your blog posts.

export const getStaticProps: GetStaticProps = async ({ params }) => {
    const blogPosts = new BlogPosts();
    return {
        props: { slugs: blogPosts.getSlugs() },
    };
};

Optionally pass in a config object to the BlogPosts() constructor (See Customization below).

/pages/blog/[...slug].tsx

export async function getStaticPaths() {
    const blogPosts = new BlogPosts();
    return {
        paths: blogPosts.getStaticPaths(),
        fallback: false,
    };
}

// Because our page is named [...slug].tsx, the context.params will have a "slug" property.
export const getStaticProps: GetStaticProps = async (context) => {
    const blogPosts = new BlogPosts();
    const blogPostData = blogPosts.getPostDataForSlug(context.params.slug);

    const frontMatter = blogPostData.data;
    const excerpt = blogPostData.excerpt;
    const body = blogPostData.body;

    return {
        props: { frontMatter, excerpt, body },
    };
};

Dependencies

  • gray-matter

Customization

You can pass in a config object. For example:

export const CONFIG: BlogPostsConfig = {
    postsRoot: "posts",
    pageParamName: "slug",
    patternToAccept: /\.md$/,
    patternToReject: /\.draft\.md$/,
};

pageParamName - Defaults to "slug". You can change this if you use a different param for your dynamic routes. See https://nextjs.org/docs/routing/dynamic-routes

patternToReject - Defaults to undefined. If you want to reject a particular file extension (e.g., for drafts), you can set the appropriate RegExp.

Author

Ron B. Yeh ([email protected]) - GameLeaf