Gatsby Plugin Build Date

1.0.0 · maintenance · verified Wed Apr 22

This Gatsby plugin, currently at version 1.0.0, provides a utility for injecting the site's build timestamp into the internal GraphQL API under the `currentBuildDate` type. It is designed to make the site's last build date accessible within components and pages, useful for displaying 'Last Updated' footers. The date is generated statically at build time, ensuring consistency across deployments. A key differentiator is its integration with the `date-and-time` library for robust date formatting and localization, which circumvents Node.js's default `toLocaleString()` limitations that typically only support 'en-US'. The plugin's release cadence is generally slow for a utility of this nature, with releases primarily focusing on stability or compatibility with new Gatsby major versions, rather than frequent feature additions. It explicitly clarifies that it's for the overall site build date, not individual file modification times.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to configure the plugin in `gatsby-config.js` with options for custom date formatting and provides a commented example of how to query and display the build date in a React component.

// In your gatsby-config.js

module.exports = {
  plugins: [
    {
      resolve: `gatsby-plugin-build-date`,
      options: {
        formatAsDateString: true, // boolean, defaults to true
        formatting: {
          format: 'YYYY-MM-DD HH:mm:ss', // ISO-like format with time
          utc: true // output time as UTC
        },
        locale: 'en' // default locale
      }
    },
  ],
}

// In a Gatsby component (e.g., in a page query or static query):
// Assuming 'data' prop is available from a page query
// or 'useStaticQuery' hook

/*
import { graphql, useStaticQuery } from 'gatsby';

function Footer() {
  const data = useStaticQuery(graphql`
    query BuildDateQuery {
      currentBuildDate {
        currentDate
      }
    }
  `);

  return (
    <footer>
      Last Built: {data.currentBuildDate.currentDate} UTC
    </footer>
  );
}

export default Footer;
*/

view raw JSON →