gatsby-plugin-advanced-sitemap-v5
It's a fork of thi plugin advanced sitemap plugin.
The difference it's :
- you have the traillingslash in the url.
- you have acces to all data from the query in the function serializer
NOTE: This plugin only generates output in production
mode! To test, run: gatsby build && gatsby serve
Install
yarn add --save gatsby-plugin-advanced-sitemap-v5
How to Use
By default this plugin will generate a single sitemap of all pages on your site, without any configuration needed.
siteMetadata: {
siteUrl: `https://www.example.com`,
},
plugins: [
`gatsby-plugin-advanced-sitemap-v5`
]
Options
If you want to generate advanced, individually organised sitemaps based on your data, you can do so by passing in a query and config. The example below uses Ghost, but this should work with any data source - including Pages, Markdown, Contentful, etc.
Example:
plugins: [
{
resolve: `gatsby-plugin-advanced-sitemap-patch`,
options: {
query: `
{
allGhostPost {
edges {
node {
id
slug
updated_at
feature_image
}
}
}
allGhostPage {
edges {
node {
id
slug
updated_at
feature_image
}
}
}
allGhostTag {
edges {
node {
id
slug
feature_image
}
}
}
allGhostAuthor {
edges {
node {
id
slug
profile_image
}
}
}
}`,
output: "/custom-sitemap.xml",
mapping: {
allGhostPost: {
sitemap: `posts`,
prefix: 'your-prefix/',
serializer: (edges,dataQuery) => {
return edges.map(({ node }) => {
(...)
})
}
},
allGhostTag: {
sitemap: `tags`,
},
allGhostAuthor: {
sitemap: `authors`,
},
allGhostPage: {
sitemap: `pages`,
},
},
exclude: [
`/dev-404-page`,
`/404`,
`/404.html`,
`/offline-plugin-app-shell-fallback`,
`/my-excluded-page`,
/(\/)?hash-\S*/,
],
createLinkInHead: true,
addUncaughtPages: true,
additionalSitemaps: [
{
name: `my-other-posts`,
url: `/blog/sitemap-posts.xml`,
},
{
url: `https://example.com/sitemap.xml`,
},
],
}
}
]