Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #100 from B77Mills/addPublicationNameLogic
Browse files Browse the repository at this point in the history
Add support for Google News Publication name
  • Loading branch information
zarathustra323 authored Jun 10, 2021
2 parents dcd7c79 + 1f3b2ff commit 3bddafc
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,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.
Expand Down
1 change: 1 addition & 0 deletions services/graphql-server/src/site-context/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = async ({
imageHost: 1,
assetHost: 1,
date: 1,
googleNewsPublicationName: 1,
};
site = await basedb.findOne('platform.Product', {
status: 1,
Expand Down
1 change: 1 addition & 0 deletions services/sitemaps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@godaddy/terminus": "^4.5.0",
"@parameter1/base-cms-env": "^2.0.0",
"@parameter1/base-cms-express-apollo": "^2.3.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",
Expand Down
3 changes: 2 additions & 1 deletion services/sitemaps/src/routes/google-news.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -54,7 +55,7 @@ const createUrl = (website, {
const parts = [
createPublication(publication.name, website.language.primaryCode),
`<news:publication_date>${moment(published).toISOString()}</news:publication_date>`,
`<news:title>${title}</news:title>`,
`<news:title>${xml.encode(title)}</news:title>`,
];
const imageParts = [];
if (images && images.length) imageParts.push(...images.map(image => createImage(image)));
Expand Down
6 changes: 4 additions & 2 deletions services/sitemaps/src/utils/create-image.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
const { xmlEntities: xml } = require('@parameter1/base-cms-html');

module.exports = ({
loc,
caption,
title,
}) => {
const parts = [];
if (caption) parts.push(`<image:caption>${caption}</image:caption>`);
if (title) parts.push(`<image:title>${title}</image:title>`);
if (caption) parts.push(`<image:caption>${xml.encode(caption)}</image:caption>`);
if (title) parts.push(`<image:title>${xml.encode(title)}</image:title>`);
return `<image:image><image:loc>${loc}</image:loc>${parts.join('')}</image:image>`;
};

0 comments on commit 3bddafc

Please sign in to comment.