Skip to content

Commit

Permalink
Merge pull request #4613 from freeletics/sitemap/allow-not-to-add-lin…
Browse files Browse the repository at this point in the history
…k-to-head

[gastby-plugin-sitemap] Add addLinkToHead option
  • Loading branch information
m-allanson authored Mar 21, 2018
2 parents 94761d3 + ab419cf commit ae3624b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sitemap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
6 changes: 4 additions & 2 deletions packages/gatsby-plugin-sitemap/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion packages/gatsby-plugin-sitemap/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-plugin-sitemap/src/internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ae3624b

Please sign in to comment.