Let's say you build a blog with Gatsby where each article is written in markdown and queried from your local filesystem with GraphQL with the help of the plugin
Now you also want to show the date of when the article was created.
So you go to Gatsby's interactive GraphQL interface (see below) and search for a field name that looks like it's a date. You find
birthTime. Sounds great! The intuition here is that the article creation date is identical to the date when the file was first created on a hard drive/file system, which is what
So you query this field and it gives you some dates that look about right. Then you render them in your frontend and everything looks great on the development server. Even when do a real build on your local machine (
gatsby build &
The surprise comes when you involve CI/CD. Let's say you deploy with Netlify. Once your site is build by Netlify based on your Git repository, you will see different dates - namely: The time it is right now!
Why is that? Remember that we said earlier that
birthTime is referring to the date when the file was first created on a hard drive/file system. Now, if you have a CI/CD service like Netlify building your site, it first fetches your repository from Github and creates all those files again on its own filesystem. Those are entirely new files! That's why their
birthTime is different.
So how can you add a creation date to your blog entries?
- Hardcode a date string into the frontmatter of your markdown files
- Use a CMS (like Netlify CMS) that offers a UI for these things, or adds dates to the data layer automatically
Just like @pentacular said: "If it's a meaningful part of the file content, it better be part of the file content."