mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
Add content to RSS
closes #886 - removed meta_description which is empty and would have crashed - added content - img src converted to absolute path - a href converted to absolute path
This commit is contained in:
parent
58873a9fc3
commit
fa43ca79d3
1 changed files with 21 additions and 10 deletions
|
@ -10,6 +10,8 @@ var Ghost = require('../../ghost'),
|
|||
_ = require('underscore'),
|
||||
errors = require('../errorHandling'),
|
||||
when = require('when'),
|
||||
url = require('url'),
|
||||
|
||||
|
||||
ghost = new Ghost(),
|
||||
frontendControllers;
|
||||
|
@ -87,7 +89,7 @@ frontendControllers = {
|
|||
description: ghost.settings('description'),
|
||||
generator: 'Ghost v' + res.locals.version,
|
||||
author: user ? user.attributes.name : null,
|
||||
feed_url: siteUrl + '/rss/',
|
||||
feed_url: url.resolve(siteUrl, '/rss/'),
|
||||
site_url: siteUrl,
|
||||
ttl: '60'
|
||||
});
|
||||
|
@ -118,16 +120,24 @@ frontendControllers = {
|
|||
ghost.doFilter('prePostsRender', page.posts, function (posts) {
|
||||
posts.forEach(function (post) {
|
||||
var item = {
|
||||
title: _.escape(post.title),
|
||||
guid: post.uuid,
|
||||
url: siteUrl + '/' + post.slug + '/',
|
||||
date: post.published_at
|
||||
};
|
||||
|
||||
if (post.meta_description !== null) {
|
||||
item.push({ description: post.meta_description });
|
||||
}
|
||||
title: _.escape(post.title),
|
||||
guid: post.uuid,
|
||||
url: siteUrl + '/' + post.slug + '/',
|
||||
date: post.published_at,
|
||||
},
|
||||
content = post.html;
|
||||
|
||||
//set img src to absolute url
|
||||
content = content.replace(/src=["|'|\s]?([\w\/\?\$\.\+\-;%:@&=,_]+)["|'|\s]?/gi, function (match, p1) {
|
||||
p1 = url.resolve(siteUrl, p1);
|
||||
return "src='" + p1 + "' ";
|
||||
});
|
||||
//set a href to absolute url
|
||||
content = content.replace(/href=["|'|\s]?([\w\/\?\$\.\+\-;%:@&=,_]+)["|'|\s]?/gi, function (match, p1) {
|
||||
p1 = url.resolve(siteUrl, p1);
|
||||
return "href='" + p1 + "' ";
|
||||
});
|
||||
item.description = content;
|
||||
feed.item(item);
|
||||
});
|
||||
res.set('Content-Type', 'text/xml');
|
||||
|
@ -138,6 +148,7 @@ frontendControllers = {
|
|||
return next(new Error(err));
|
||||
});
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
module.exports = frontendControllers;
|
Loading…
Add table
Reference in a new issue