diff --git a/docs/docs/creating-a-sitemap.md b/docs/docs/creating-a-sitemap.md index fa69df1890e56..cfa851bf4c5f8 100644 --- a/docs/docs/creating-a-sitemap.md +++ b/docs/docs/creating-a-sitemap.md @@ -26,6 +26,8 @@ module.exports = { } ``` +**Note:** The siteUrl property must be defined and not left empty. + Next run a build (`npm run build`) since the sitemap generation will only happen for production builds. This is all that's required to get a working sitemap with Gatsby! By default, the generated sitemap path is /sitemap.xml and will include all of your site’s pages, but of course the plugin exposes options to configure this default functionality. ### Additional Modification diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index 58b8861480c7b..6fbec801358ed 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -28,9 +28,14 @@ export const runQuery = (handler, query, excludes, pathPrefix) => return page }) - if (!r.data.site.siteMetadata.siteUrl) { + // siteUrl Validation + if ( + !r.data.site.siteMetadata.siteUrl || + r.data.site.siteMetadata.siteUrl == null || + r.data.site.siteMetadata.siteUrl.trim().length == 0 + ) { throw new Error( - `SiteMetaData 'siteUrl' property is required. Check out the documentation to see a working example: https://www.gatsbyjs.org/packages/gatsby-plugin-sitemap/#how-to-use` + `SiteMetaData 'siteUrl' property is required and cannot be left empty. Check out the documentation to see a working example: https://www.gatsbyjs.org/packages/gatsby-plugin-sitemap/#how-to-use` ) }