From 8557c01bc6caa90934a5477005234d900247a06f Mon Sep 17 00:00:00 2001 From: Brian Miller Date: Wed, 9 Jun 2021 10:44:05 -0500 Subject: [PATCH 1/8] Add ability to pass publicationName to googleSiteMap --- services/sitemaps/src/routes/google-news.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/services/sitemaps/src/routes/google-news.js b/services/sitemaps/src/routes/google-news.js index d277d792a..b279b4515 100644 --- a/services/sitemaps/src/routes/google-news.js +++ b/services/sitemaps/src/routes/google-news.js @@ -48,11 +48,12 @@ const createUrl = (website, { published, publication, images, -}) => { +}, publicationName) => { // News requires a publication, a published date and a title. - if (!publication || !published || !title) return null; + if ((!publication && !publicationName) || !published || !title) return null; + const name = (publicationName) || publication.name; const parts = [ - createPublication(publication.name, website.language.primaryCode), + createPublication(name, website.language.primaryCode), `${moment(published).toISOString()}`, `${title}`, ]; @@ -63,6 +64,8 @@ const createUrl = (website, { module.exports = asyncRoute(async (req, res) => { const input = parseJson(req.get('x-google-news-input') || '{}'); + const { publicationName } = input; + delete input.publicationName; const variables = input ? { input } : undefined; const { apollo, websiteContext: website } = res.locals; @@ -76,7 +79,7 @@ module.exports = asyncRoute(async (req, res) => { .setAttr('xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1') .setAttr('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') .setAttr('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-news/0.9 http://www.google.com/schemas/sitemap-news/0.9/sitemap-news.xsd') - .setUrls(contentSitemapNewsUrls.map(url => createUrl(website, url))); + .setUrls(contentSitemapNewsUrls.map(url => createUrl(website, url, publicationName))); res.end(urlset.build()); }); From 2fda742907b642b926d77dbf7ee5715c671ab8eb Mon Sep 17 00:00:00 2001 From: Brian Miller Date: Wed, 9 Jun 2021 12:00:11 -0500 Subject: [PATCH 2/8] Ensure TItle, ImageTitle & ImageCaption are encoded Ensure that the Title, Image Title & Image Caption are xml encoded to prevent & in title from breaking the xml --- services/sitemaps/package.json | 1 + services/sitemaps/src/routes/google-news.js | 3 ++- services/sitemaps/src/utils/create-image.js | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/sitemaps/package.json b/services/sitemaps/package.json index 780e337e8..95779ebff 100644 --- a/services/sitemaps/package.json +++ b/services/sitemaps/package.json @@ -16,6 +16,7 @@ "@parameter1/base-cms-env": "^2.0.0", "@parameter1/base-cms-express-apollo": "^2.3.0", "@parameter1/base-cms-tenant-context": "^2.0.0", + "@parameter1/base-cms-html": "^2.0.0", "@parameter1/base-cms-utils": "^2.22.2", "@parameter1/base-cms-web-common": "^2.22.2", "express": "^4.17.1", diff --git a/services/sitemaps/src/routes/google-news.js b/services/sitemaps/src/routes/google-news.js index b279b4515..5a6d16bed 100644 --- a/services/sitemaps/src/routes/google-news.js +++ b/services/sitemaps/src/routes/google-news.js @@ -1,4 +1,5 @@ const { asyncRoute } = require('@parameter1/base-cms-utils'); +const { xmlEntities: xml } = require('@parameter1/base-cms-html'); const gql = require('graphql-tag'); const moment = require('moment'); const createImage = require('../utils/create-image'); @@ -55,7 +56,7 @@ const createUrl = (website, { const parts = [ createPublication(name, website.language.primaryCode), `${moment(published).toISOString()}`, - `${title}`, + `${xml.encode(title)}`, ]; const imageParts = []; if (images && images.length) imageParts.push(...images.map(image => createImage(image))); diff --git a/services/sitemaps/src/utils/create-image.js b/services/sitemaps/src/utils/create-image.js index 9565da852..f37d157ae 100644 --- a/services/sitemaps/src/utils/create-image.js +++ b/services/sitemaps/src/utils/create-image.js @@ -1,10 +1,12 @@ +const { xmlEntities: xml } = require('@parameter1/base-cms-html'); + module.exports = ({ loc, caption, title, }) => { const parts = []; - if (caption) parts.push(`${caption}`); - if (title) parts.push(`${title}`); + if (caption) parts.push(`${xml.encode(caption)}`); + if (title) parts.push(`${xml.encode(title)}`); return `${loc}${parts.join('')}`; }; From 74bfe3973b0b2ffa3dad8962d354590b919e626d Mon Sep 17 00:00:00 2001 From: Brian Miller Date: Wed, 9 Jun 2021 12:55:21 -0500 Subject: [PATCH 3/8] Use new header instead of messing with query input --- services/sitemaps/src/routes/google-news.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/sitemaps/src/routes/google-news.js b/services/sitemaps/src/routes/google-news.js index 5a6d16bed..51dc51664 100644 --- a/services/sitemaps/src/routes/google-news.js +++ b/services/sitemaps/src/routes/google-news.js @@ -65,8 +65,7 @@ const createUrl = (website, { module.exports = asyncRoute(async (req, res) => { const input = parseJson(req.get('x-google-news-input') || '{}'); - const { publicationName } = input; - delete input.publicationName; + const publicationName = req.get('x-google-news-publication-name'); const variables = input ? { input } : undefined; const { apollo, websiteContext: website } = res.locals; From 21d03334c5aedafb1b11612931c5fafb8cb45ad3 Mon Sep 17 00:00:00 2001 From: Brian Miller Date: Wed, 9 Jun 2021 15:31:32 -0500 Subject: [PATCH 4/8] update how const are set/structured --- services/sitemaps/src/routes/google-news.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services/sitemaps/src/routes/google-news.js b/services/sitemaps/src/routes/google-news.js index 51dc51664..ceca44fa3 100644 --- a/services/sitemaps/src/routes/google-news.js +++ b/services/sitemaps/src/routes/google-news.js @@ -43,16 +43,17 @@ const createPublication = (name, language) => { return `${parts.join('')}`; }; -const createUrl = (website, { - loc, - title, - published, - publication, - images, -}, publicationName) => { +const createUrl = (website, url, publicationName) => { + const { + loc, + title, + published, + publication, + images, + } = url; + const name = publicationName || publication.name; // News requires a publication, a published date and a title. if ((!publication && !publicationName) || !published || !title) return null; - const name = (publicationName) || publication.name; const parts = [ createPublication(name, website.language.primaryCode), `${moment(published).toISOString()}`, From 4551087ea3152a1d4f223d799eb95aec4f52801d Mon Sep 17 00:00:00 2001 From: Brian Miller Date: Wed, 9 Jun 2021 16:22:11 -0500 Subject: [PATCH 5/8] fix if check --- services/sitemaps/src/routes/google-news.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/sitemaps/src/routes/google-news.js b/services/sitemaps/src/routes/google-news.js index ceca44fa3..a1d85fde9 100644 --- a/services/sitemaps/src/routes/google-news.js +++ b/services/sitemaps/src/routes/google-news.js @@ -53,7 +53,7 @@ const createUrl = (website, url, publicationName) => { } = url; const name = publicationName || publication.name; // News requires a publication, a published date and a title. - if ((!publication && !publicationName) || !published || !title) return null; + if (!name || !published || !title) return null; const parts = [ createPublication(name, website.language.primaryCode), `${moment(published).toISOString()}`, From 2503bb7e6dedf6041456a9eddb80a6c394fa086a Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 10 Jun 2021 09:07:06 -0500 Subject: [PATCH 6/8] Change order of html package --- services/sitemaps/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/sitemaps/package.json b/services/sitemaps/package.json index 95779ebff..623ecdd73 100644 --- a/services/sitemaps/package.json +++ b/services/sitemaps/package.json @@ -15,8 +15,8 @@ "@godaddy/terminus": "^4.5.0", "@parameter1/base-cms-env": "^2.0.0", "@parameter1/base-cms-express-apollo": "^2.3.0", - "@parameter1/base-cms-tenant-context": "^2.0.0", "@parameter1/base-cms-html": "^2.0.0", + "@parameter1/base-cms-tenant-context": "^2.0.0", "@parameter1/base-cms-utils": "^2.22.2", "@parameter1/base-cms-web-common": "^2.22.2", "express": "^4.17.1", From f59fb15c0155481bf6e9697aa3618298cb96712b Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 10 Jun 2021 09:22:46 -0500 Subject: [PATCH 7/8] Use `googleNewsPublicationName` if present --- .../src/graphql/resolvers/platform/content.js | 7 +++++++ services/graphql-server/src/site-context/load.js | 1 + 2 files changed, 8 insertions(+) diff --git a/services/graphql-server/src/graphql/resolvers/platform/content.js b/services/graphql-server/src/graphql/resolvers/platform/content.js index 03f9fdc0a..0380e0201 100644 --- a/services/graphql-server/src/graphql/resolvers/platform/content.js +++ b/services/graphql-server/src/graphql/resolvers/platform/content.js @@ -641,6 +641,13 @@ module.exports = { images: (content, _, { basedb }) => loadSitemapImages({ content, basedb }), }, + /** + * + */ + ContentSitemapNewsPublication: { + name: ({ name, googleNewsPublicationName }) => googleNewsPublicationName || name, + }, + ContentSitemapImage: { loc: (image, _, { site }) => { // Use site image host otherwise fallback to global default. diff --git a/services/graphql-server/src/site-context/load.js b/services/graphql-server/src/site-context/load.js index c0d13bce7..29f48bded 100644 --- a/services/graphql-server/src/site-context/load.js +++ b/services/graphql-server/src/site-context/load.js @@ -32,6 +32,7 @@ module.exports = async ({ imageHost: 1, assetHost: 1, date: 1, + googleNewsPublicationName: 1, }; site = await basedb.findOne('platform.Product', { status: 1, From 1f3b2ff430e268edc1830873cbd32b2ad4cbb9d7 Mon Sep 17 00:00:00 2001 From: Jacob Bare Date: Thu, 10 Jun 2021 09:25:19 -0500 Subject: [PATCH 8/8] Revert publication name handling --- services/sitemaps/src/routes/google-news.js | 23 +++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/services/sitemaps/src/routes/google-news.js b/services/sitemaps/src/routes/google-news.js index a1d85fde9..13f25210f 100644 --- a/services/sitemaps/src/routes/google-news.js +++ b/services/sitemaps/src/routes/google-news.js @@ -43,19 +43,17 @@ const createPublication = (name, language) => { return `${parts.join('')}`; }; -const createUrl = (website, url, publicationName) => { - const { - loc, - title, - published, - publication, - images, - } = url; - const name = publicationName || publication.name; +const createUrl = (website, { + loc, + title, + published, + publication, + images, +}) => { // News requires a publication, a published date and a title. - if (!name || !published || !title) return null; + if (!publication || !published || !title) return null; const parts = [ - createPublication(name, website.language.primaryCode), + createPublication(publication.name, website.language.primaryCode), `${moment(published).toISOString()}`, `${xml.encode(title)}`, ]; @@ -66,7 +64,6 @@ const createUrl = (website, url, publicationName) => { module.exports = asyncRoute(async (req, res) => { const input = parseJson(req.get('x-google-news-input') || '{}'); - const publicationName = req.get('x-google-news-publication-name'); const variables = input ? { input } : undefined; const { apollo, websiteContext: website } = res.locals; @@ -80,7 +77,7 @@ module.exports = asyncRoute(async (req, res) => { .setAttr('xmlns:image', 'http://www.google.com/schemas/sitemap-image/1.1') .setAttr('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') .setAttr('xsi:schemaLocation', 'http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd http://www.google.com/schemas/sitemap-news/0.9 http://www.google.com/schemas/sitemap-news/0.9/sitemap-news.xsd') - .setUrls(contentSitemapNewsUrls.map(url => createUrl(website, url, publicationName))); + .setUrls(contentSitemapNewsUrls.map(url => createUrl(website, url))); res.end(urlset.build()); });