gatsby-plugin-advanced-sitemap-v-2
The default Gatsby sitemap plugin generates a simple blob of raw XML for all your pages. This advanced sitemap plugin adds more power and configuration, generating a single or multiple sitemaps with full XSL templates to make them neatly organised and human + machine readable, as well linking image resources to encourage media indexing.
Demo: https://gatsby.ghost.org/sitemap.xml
NOTE: This plugin only generates output in production
mode! To test, run: gatsby build && gatsby serve
Install
`npm install --save gatsby-plugin-advanced-sitemap-v-2
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-v-2`
]
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-v-2`,
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) => {
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`,
},
],
}
}
]
Example output of ☝️ this exact config 👉 https://gatsby.ghost.org/sitemap.xml
Develop Plugin
- Install dependencies
yarn install
Build Plugin
yarn build
Run Tests
yarn test
Copyright & License
Copyright (c) 2013-2022 Ghost Foundation - Released under the MIT license.