Gatsby Sitemap
by John Vincent
Posted on September 22, 2019
Building a sitemap
file with Gatsby is straightforward.
Gatsby Sitemap Plugin
Using the plugin gatsby-plugin-sitemap
, add to gatsby-config.js
{
resolve: `gatsby-plugin-sitemap`,
options: {
query: `
{
site {
siteMetadata {
siteUrl
}
}
allSitePage(sort: {fields: path}) {
edges {
node {
path
}
}
}
}`,
serialize: ({ site, allSitePage }) => {
const result = allSitePage.edges
.filter((item) => {
if (item.node.path === `/thanks/`) {
return false;
}
if (item.node.path.startsWith(`/private/`)) {
return false;
}
return true;
})
.map((edge) => ({
url: site.siteMetadata.siteUrl + edge.node.path,
changefreq: `daily`,
priority: 0.7,
}));
return result;
},
},
},
The sitemap.xml
file will be build only for production builds.
Gatsby
- Configuring Google Domains
- Configuring Google Domains
- Configuring Meta Tags
- Feediator Google Authentication
- Gatsby Robots file
- Gatsby Sitemap
- Google Authentication
- Google Coverage Issues
- Google Custom Search and Jekyll
- Google Fonts and Webfontloader
- Google Gmail Configuration
- Google Mobile Usability Issues
- Google Youtube APIs
- Website Review Reference