Skip to content

Commit

Permalink
feat(gatsby-plugin-sitemap): add siteUrl validation (#16329)
Browse files Browse the repository at this point in the history
* empty sitemap Url validation

* creating awareness for siteUrl validation

* site url validation

* url validation fix

* Update creating-a-sitemap.md

* Update internals.js
  • Loading branch information
doc-han authored and GatsbyJS Bot committed Aug 9, 2019
1 parent f2b0e53 commit 9f3d71d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/docs/creating-a-sitemap.md
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions packages/gatsby-plugin-sitemap/src/internals.js
Expand Up @@ -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`
)
}

Expand Down

0 comments on commit 9f3d71d

Please sign in to comment.