diff --git a/packages/gatsby-plugin-sitemap/README.md b/packages/gatsby-plugin-sitemap/README.md index dd5c33da85416..e38bfc2022ca2 100644 --- a/packages/gatsby-plugin-sitemap/README.md +++ b/packages/gatsby-plugin-sitemap/README.md @@ -25,7 +25,7 @@ generated sitemap will include all of your site's pages, except the ones you exc ## Options -The `defaultOptions` [here](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-sitemap/src/internals.js#L15) can be overridden. +The `defaultOptions` [here](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-sitemap/src/internals.js#L20) can be overridden. We _ALWAYS_ exclude the following pages: `/dev-404-page/`,`/404` &`/offline-plugin-app-shell-fallback/`, this cannot be changed. diff --git a/packages/gatsby-plugin-sitemap/src/gatsby-node.js b/packages/gatsby-plugin-sitemap/src/gatsby-node.js index 0e1b90e834889..addadeb22dfc3 100644 --- a/packages/gatsby-plugin-sitemap/src/gatsby-node.js +++ b/packages/gatsby-plugin-sitemap/src/gatsby-node.js @@ -5,11 +5,13 @@ import { defaultOptions, runQuery, writeFile } from "./internals" const publicPath = `./public` exports.onPostBuild = async ({ graphql }, pluginOptions) => { - delete pluginOptions.plugins + const options = { ...pluginOptions } + delete options.plugins + delete options.addLinkToHead const { query, serialize, output, exclude, ...rest } = { ...defaultOptions, - ...pluginOptions, + ...options, } const map = sitemap.createSitemap(rest) diff --git a/packages/gatsby-plugin-sitemap/src/gatsby-ssr.js b/packages/gatsby-plugin-sitemap/src/gatsby-ssr.js index 052232134c956..0642ecdbde94e 100644 --- a/packages/gatsby-plugin-sitemap/src/gatsby-ssr.js +++ b/packages/gatsby-plugin-sitemap/src/gatsby-ssr.js @@ -3,7 +3,12 @@ import { withPrefix } from "gatsby-link" import { defaultOptions } from "./internals" exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => { - let { output } = { ...defaultOptions, ...pluginOptions } + let { output, addLinkToHead } = { ...defaultOptions, ...pluginOptions } + + if (!addLinkToHead) { + return + } + if (output.charAt(0) !== `/`) { output = `/` + output } diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index 15c4d4f25cc64..8255d27a3213b 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -36,6 +36,7 @@ export const defaultOptions = { }`, output: `/sitemap.xml`, exclude: [`/dev-404-page`, `/404`, `/offline-plugin-app-shell-fallback`], + addLinkToHead: true, serialize: ({ site, allSitePage }) => allSitePage.edges.map(edge => { return {