From cec1ff4d9d3539c8a7cc713d1c068ed87292b5d0 Mon Sep 17 00:00:00 2001 From: Farhan Yahya Date: Fri, 2 Aug 2019 11:13:04 +0000 Subject: [PATCH 1/6] empty sitemap Url validation --- packages/gatsby-plugin-sitemap/src/internals.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index 58b8861480c7..295654b3dfb9 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -28,11 +28,18 @@ export const runQuery = (handler, query, excludes, pathPrefix) => return page }) + // siteUrl Validation if (!r.data.site.siteMetadata.siteUrl) { 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` ) } + + if(r.data.site.siteMetadata.siteUrl!=null || r.data.site.siteMetadata.siteUrl.trim()!="") { + throw new Error( + `SiteMetaData 'siteUrl' property can't be left empty, site's url is required. Check out the documentation to see a working example: https://www.gatsbyjs.org/packages/gatsby-plugin-sitemap/#how-to-use` + ) + } // remove trailing slash of siteUrl r.data.site.siteMetadata.siteUrl = withoutTrailingSlash( From f51c4d266fafea870ba2cb414fc65cd7ec4abdb0 Mon Sep 17 00:00:00 2001 From: Farhan Yahya Date: Fri, 2 Aug 2019 11:54:06 +0000 Subject: [PATCH 2/6] creating awareness for siteUrl validation --- docs/docs/creating-a-sitemap.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/creating-a-sitemap.md b/docs/docs/creating-a-sitemap.md index fa69df1890e5..d95151957473 100644 --- a/docs/docs/creating-a-sitemap.md +++ b/docs/docs/creating-a-sitemap.md @@ -25,6 +25,7 @@ module.exports = { plugins: [`gatsby-plugin-sitemap`], } ``` +**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. From d6d060160ee4c6afad4aa8780e51b350a87d6d30 Mon Sep 17 00:00:00 2001 From: Farhan Yahya Date: Fri, 2 Aug 2019 14:36:17 +0000 Subject: [PATCH 3/6] site url validation --- packages/gatsby-plugin-sitemap/src/internals.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index 295654b3dfb9..7fbc2fe7e3b2 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -34,8 +34,11 @@ export const runQuery = (handler, query, excludes, pathPrefix) => `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` ) } - - if(r.data.site.siteMetadata.siteUrl!=null || r.data.site.siteMetadata.siteUrl.trim()!="") { + + if ( + r.data.site.siteMetadata.siteUrl == null || + r.data.site.siteMetadata.siteUrl.trim() == "" + ) { throw new Error( `SiteMetaData 'siteUrl' property can't be left empty, site's url is required. Check out the documentation to see a working example: https://www.gatsbyjs.org/packages/gatsby-plugin-sitemap/#how-to-use` ) From 0e188913639d3c4d7f51d495ad5e7f561a20ab20 Mon Sep 17 00:00:00 2001 From: Farhan Yahya Date: Fri, 2 Aug 2019 15:02:35 +0000 Subject: [PATCH 4/6] url validation fix --- packages/gatsby-plugin-sitemap/src/internals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index 7fbc2fe7e3b2..2bf9923b7306 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -37,7 +37,7 @@ export const runQuery = (handler, query, excludes, pathPrefix) => if ( r.data.site.siteMetadata.siteUrl == null || - r.data.site.siteMetadata.siteUrl.trim() == "" + r.data.site.siteMetadata.siteUrl.trim().length == 0 ) { throw new Error( `SiteMetaData 'siteUrl' property can't be left empty, site's url is required. Check out the documentation to see a working example: https://www.gatsbyjs.org/packages/gatsby-plugin-sitemap/#how-to-use` From 5819e1f8348ab8d4b806412c988c08fe622c1f93 Mon Sep 17 00:00:00 2001 From: Farhan Yahya Date: Fri, 2 Aug 2019 15:39:55 +0000 Subject: [PATCH 5/6] Update creating-a-sitemap.md --- docs/docs/creating-a-sitemap.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/docs/creating-a-sitemap.md b/docs/docs/creating-a-sitemap.md index d95151957473..cfa851bf4c5f 100644 --- a/docs/docs/creating-a-sitemap.md +++ b/docs/docs/creating-a-sitemap.md @@ -25,6 +25,7 @@ module.exports = { plugins: [`gatsby-plugin-sitemap`], } ``` + **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. From f91eda9420a50d83d0f26574308f27bd9b475583 Mon Sep 17 00:00:00 2001 From: Farhan Yahya Date: Tue, 6 Aug 2019 23:54:26 +0000 Subject: [PATCH 6/6] Update internals.js --- packages/gatsby-plugin-sitemap/src/internals.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/gatsby-plugin-sitemap/src/internals.js b/packages/gatsby-plugin-sitemap/src/internals.js index 2bf9923b7306..6fbec801358e 100644 --- a/packages/gatsby-plugin-sitemap/src/internals.js +++ b/packages/gatsby-plugin-sitemap/src/internals.js @@ -29,18 +29,13 @@ export const runQuery = (handler, query, excludes, pathPrefix) => }) // siteUrl Validation - if (!r.data.site.siteMetadata.siteUrl) { - 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` - ) - } - 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 can't be left empty, site's url 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` ) }