Skip to content

Commit 9f3d71d

Browse files
doc-hanGatsbyJS Bot
authored and
GatsbyJS Bot
committed
feat(gatsby-plugin-sitemap): add siteUrl validation (#16329)
* empty sitemap Url validation * creating awareness for siteUrl validation * site url validation * url validation fix * Update creating-a-sitemap.md * Update internals.js
1 parent f2b0e53 commit 9f3d71d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

docs/docs/creating-a-sitemap.md

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ module.exports = {
2626
}
2727
```
2828

29+
**Note:** The siteUrl property must be defined and not left empty.
30+
2931
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.
3032

3133
### Additional Modification

packages/gatsby-plugin-sitemap/src/internals.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ export const runQuery = (handler, query, excludes, pathPrefix) =>
2828
return page
2929
})
3030

31-
if (!r.data.site.siteMetadata.siteUrl) {
31+
// siteUrl Validation
32+
if (
33+
!r.data.site.siteMetadata.siteUrl ||
34+
r.data.site.siteMetadata.siteUrl == null ||
35+
r.data.site.siteMetadata.siteUrl.trim().length == 0
36+
) {
3237
throw new Error(
33-
`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`
38+
`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`
3439
)
3540
}
3641

0 commit comments

Comments
 (0)