GatsbyJS - Last Updated
In gatsby-node.js
, add modifiedTime
, which can be derived from parent node (File
), to MarkdownRemark
node:
exports.onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `MarkdownRemark`) {
// ...
const parent = getNode(node.parent);
createNodeField({
node,
name: `modifiedTime`,
value: parent.modifiedTime.slice(0, 10),
});
}
};
Then query it like this:
query($slug: String!) {
markdownRemark(fields: { slug: { eq: $slug } }) {
...
fields {
modifiedTime
}
}
}