Created
January 10, 2023 21:56
-
-
Save juanlugm/817b51016052088c91994e0180119562 to your computer and use it in GitHub Desktop.
gatsby-plugin-sitemap configuration for markdown pages with lastmod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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