Skip to content

Instantly share code, notes, and snippets.

@juanlugm
Created January 10, 2023 21:56
Show Gist options
  • Save juanlugm/817b51016052088c91994e0180119562 to your computer and use it in GitHub Desktop.
Save juanlugm/817b51016052088c91994e0180119562 to your computer and use it in GitHub Desktop.
gatsby-plugin-sitemap configuration for markdown pages with lastmod
{
resolve: `gatsby-plugin-sitemap`,
options: {
query: `{
site {
siteMetadata {
siteUrl
}
}
allSitePage {
nodes {
path
}
}
allMarkdownRemark {
edges {
node {
fields {
slug
}
frontmatter {
date(formatString: "YYYY-MM-DD")
}
}
}
}
}`,
resolvePages: ({
allSitePage: { nodes: allPages },
allMarkdownRemark: { edges: allMarkdownEdges },
}) => {
const markdownNodeMap = allMarkdownEdges.reduce((acc, edge) => {
acc[edge.node.fields.slug] = edge.node.frontmatter
return acc
}, {})
return allPages.map(page => {
return { ...page, ...markdownNodeMap[page.path] }
})
},
serialize: ({ path, date }) => {
return {
url: path,
changefreq: `daily`,
priority: 0.7,
lastmod: date,
}
},
},
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment