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

gatsby-plugin-changelog-context

v1.1.0

Published

Automate adding a changelog of commit history to your Gatsby -generated pages.

Readme

gatsby-plugin-changelog-context

Automate adding a changelog of commit history to your Gatsby -generated pages.


PRs Welcome Maintenance NPM version NPM license Build Status semantic-release


Each page's commit history is added to your page templates via the page context. This then gives you the ability to display/consume this data within your page template however you like.

Perquisites

This Gatsby plugin requires the location of each page with respect to the filesystem, as stored in git; This is to ensure we get the correct/relevant commit history for the page from git.

This fits with a common workflow in a typical Gatsby setup, when programmatically generating pages. How to add this data is provided in more detail below.

Install

Add Dependency

Install using yarn/npm

npm install --save gatsby-plugin-changelog-context
# or
yarn add gatsby-plugin-changelog-context

and add the plugin to your config file:

Add Plugin to GatsbyJS Site

// gatsby-config.js
module.exports = {
  ...
  plugins: [
    'gatsby-plugin-changelog-context',
  ]
};

Adding Filesystem Data to your Page Query

To ensure you get only commits for each page, separately, you need to ensure that your pages include the absolute path to the file containing the content, e.g. the Markdown file. You can do this by including the edges.node.fileAbsolutePath parameter in your GraphQL query.

For example, when programmatically generating pages from Markdown files, you can modify your createPages node API call to add the required data:

const { data, errors } = await graphql(`
  {
    allMarkdownRemark(sort: { fields: [frontmatter___date], order: DESC }) {
      edges {
        node {
          fileAbsolutePath
          fields {
            slug
          }
          frontmatter {
            title
          }
        }
      }
    }
  }
`);

// ...

const blogPostTemplate = path.resolve('./src/templates/blog-post.js');

data.allMarkdownRemark.edges.forEach(post => {
  createPage({
    path: post.node.fields.slug,
    component: blogPostTemplate,
    context: {
      slug: post.node.fields.slug,
      // required for [gatsby-plugin-changelog-context]
      fileAbsolutePath: post.node.fileAbsolutePath,
    },
  });
});

Options

The following options are supported:

| key | type | Description | | :-: | :------: | :---------------------------------------------------------------------------------------------------------------------------------------------: | | git | object | Options to be passed to the git CLI, e.g. --date. See the git log docs for details of available options |

Example

As an example, to configure the commit date format to be a unix timestamp (the default is ISO8601):

// gatsby-config.js
module.exports = {
  ...
  plugins: [
    {
      resolve: 'gatsby-plugin-changelog-context',
      options: {
        git: {
          '--date': 'unix',
        },
      },
    },
  ]
};

Usage

The commit history for each page is accessed from the page template's pageContext. In the above example, which uses a page template, called blogPostTemplate, we can access the commit history via the props.pageContext.changelog:

const BlogPostTemplate = ({ data, pageContext }) => {
  // ...

  <section>
    <h4>Changelog</h4>

    {pageContext.changelog.map(({ hash, date, message }) => (
      <p key={hash}>
        {moment(date).format('ddd Do MMM, YYYY')} - {message}
      </p>
    ))}
  </section>;

  // ...
};

The changelog pageContext prop has the following type signature:

const changelog: Commit[]; // Empty array, or array of Commit objects

// Commit object
interface Commit {
  hash: string; // commit hash
  data: string; // ISO datetime
  message: string; // commit summary
  body: string; // commit body
  author_name: string;
  author_email: string;
  refs: string;
}

Credit

This plugin was inspired by a tweet from Søren Birkemeyer: