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 #345 from Shinsina/rss-feed-cleanup
Browse files Browse the repository at this point in the history
Encode HTML ampersand entities in image query string
  • Loading branch information
zarathustra323 authored Jun 20, 2022
2 parents 70a26c3 + 1c6b671 commit 0ea12b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion services/rss/src/routes/all-published-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = asyncRoute(async (req, res) => {
const { edges } = data.allPublishedContent;

const parts = [
'<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">',
'<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">',
createChannel({
title: channel.title || `Published Content Feed | ${website.name}`,
link: channel.link || website.origin,
Expand Down
4 changes: 2 additions & 2 deletions services/rss/src/routes/website-scheduled-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = asyncRoute(async (req, res) => {
const { section, edges } = data.websiteScheduledContent;

const parts = [
'<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">',
'<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">',
createChannel({
title: channel.title || `${section.fullName || section.name} | ${website.name}`,
link: channel.link || `${website.origin}${section.canonicalPath}`,
Expand All @@ -58,5 +58,5 @@ module.exports = asyncRoute(async (req, res) => {
}),
'</rss>',
];
res.end(parts.join(''));
res.end(parts.join('\n'));
});
2 changes: 1 addition & 1 deletion services/rss/src/utils/create-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ module.exports = ({
`<description>${xml.encode(description)}</description>`,
];
if (language) parts.push(`<language>${language}</language>`);
return `<channel>${parts.join('')}${items.join('')}</channel>`;
return `<channel>${parts.join('\n')}${items.join('\n')}</channel>`;
};
6 changes: 4 additions & 2 deletions services/rss/src/utils/create-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ module.exports = ({
}
const imageMediaTags = getAsArray(images, 'edges').reduce((arr, { node }) => {
const { src } = node;
if (src) arr.push(`<media:content url="${node.src}" medium="image" />`);
if (src) {
arr.push(`<media:content url="${src.replace(/&([a-z0-9-_]+=)/gi, '&amp;$1')}" medium="image" />`);
}
return arr;
}, []);
if (imageMediaTags.length) parts.push(...imageMediaTags);
if (embedSrc) parts.push(`<media:content url="${embedSrc}" medium="video" />`);
return `<item>${parts.join('')}</item>`;
return `<item>${parts.join('\n')}</item>`;
};

0 comments on commit 0ea12b9

Please sign in to comment.