December 21, 2019
If your Gatsby site pulls in data at build time, it can be helpful to show visitors when the site was last built.
This component relies on a GraphQL query to fetch the build time, and then formats it using a lightweight package called tiny-relative-date.
Here is an abbreviated component using it (without styling):
import React from "react"
import { useStaticQuery, graphql } from "gatsby"
import relativeDate from "tiny-relative-date"
export default () => {
const query = useStaticQuery(graphql`
query {
site {
buildTime
}
}
`)
const buildTime = new Date(query.site.buildTime)
const buildTimeRelative = relativeDate(buildTime)
return (
<p>This site was last built {buildTimeRelative}.</p>
)
}
Tufts Meal Plan Wrapped
Mar 2, 2024
Building an e-ink picture frame that displays an iCloud photo album
Jan 9, 2024
2023 in review
Jan 5, 2024
Subscribe to my newsletter for a monthly round-up of new blog posts and projects Iām working on!