0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Merge pull request #4025 from mvalipour/master

URL replacement in RSS feed mucks with content
This commit is contained in:
Hannah Wolfe 2014-09-15 20:35:18 +01:00
commit aa0d9fda46
2 changed files with 14 additions and 14 deletions

View file

@ -14,6 +14,7 @@ var moment = require('moment'),
filters = require('../../server/filters'),
template = require('../helpers/template'),
errors = require('../errors'),
cheerio = require('cheerio'),
frontendControllers,
staticPostPermalink,
@ -485,23 +486,21 @@ frontendControllers = {
categories: _.pluck(post.tags, 'name'),
author: post.author ? post.author.name : null
},
content = post.html;
htmlContent = cheerio.load(post.html, { decodeEntities: false });
//set img src to absolute url
content = content.replace(/src=["|'|\s]?([\w\/\?\$\.\+\-;%:@&=,_]+)["|'|\s]?/gi, function (match, p1) {
/*jslint unparam:true*/
p1 = url.resolve(siteUrl, p1);
return "src='" + p1 + "' ";
// convert relative resource urls to absolute
['href', 'src'].forEach(function (attributeName) {
htmlContent('[' + attributeName + ']').each(function (ix, el) {
el = htmlContent(el);
var attributeValue = el.attr(attributeName);
attributeValue = url.resolve(siteUrl, attributeValue);
el.attr(attributeName, attributeValue);
});
});
//set a href to absolute url
content = content.replace(/href=["|'|\s]?([\w\/\?\$\.\+\-;%:@&=,_]+)["|'|\s]?/gi, function (match, p1) {
/*jslint unparam:true*/
p1 = url.resolve(siteUrl, p1);
return "href='" + p1 + "' ";
});
item.description = content;
item.description = htmlContent.html();
feed.item(item);
});
}).then(function () {

View file

@ -36,6 +36,7 @@
"body-parser": "1.6.3",
"bookshelf": "0.7.6",
"busboy": "0.2.3",
"cheerio": "0.17.0",
"colors": "0.6.2",
"compression": "^1.0.2",
"connect": "3.0.0-rc.1",