Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-plugin-sitemap): add siteUrl validation #16329

Merged
merged 6 commits into from Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 (
doc-han marked this conversation as resolved.
Show resolved Hide resolved
!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