mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Do not show internal tags in RSS feed (#7385)
closes #7367 - checks tags are visibile if internal tags are enabled in labs - dirty quick update to tests
This commit is contained in:
parent
215185bc52
commit
1cf0b940ad
2 changed files with 92 additions and 4 deletions
|
@ -1,17 +1,18 @@
|
||||||
var _ = require('lodash'),
|
var crypto = require('crypto'),
|
||||||
crypto = require('crypto'),
|
|
||||||
downsize = require('downsize'),
|
downsize = require('downsize'),
|
||||||
RSS = require('rss'),
|
RSS = require('rss'),
|
||||||
config = require('../../../config'),
|
config = require('../../../config'),
|
||||||
errors = require('../../../errors'),
|
errors = require('../../../errors'),
|
||||||
filters = require('../../../filters'),
|
filters = require('../../../filters'),
|
||||||
processUrls = require('../../../utils/make-absolute-urls'),
|
processUrls = require('../../../utils/make-absolute-urls'),
|
||||||
|
labs = require('../../../utils/labs'),
|
||||||
|
|
||||||
// Really ugly temporary hack for location of things
|
// Really ugly temporary hack for location of things
|
||||||
fetchData = require('../../../controllers/frontend/fetch-data'),
|
fetchData = require('../../../controllers/frontend/fetch-data'),
|
||||||
|
|
||||||
generate,
|
generate,
|
||||||
generateFeed,
|
generateFeed,
|
||||||
|
generateTags,
|
||||||
getFeedXml,
|
getFeedXml,
|
||||||
feedCache = {};
|
feedCache = {};
|
||||||
|
|
||||||
|
@ -77,6 +78,19 @@ getFeedXml = function getFeedXml(path, data) {
|
||||||
return feedCache[path].xml;
|
return feedCache[path].xml;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
generateTags = function generateTags(data) {
|
||||||
|
if (data.tags) {
|
||||||
|
return data.tags.reduce(function (tags, tag) {
|
||||||
|
if (tag.visibility !== 'internal' || !labs.isSet('internalTags')) {
|
||||||
|
tags.push(tag.name);
|
||||||
|
}
|
||||||
|
return tags;
|
||||||
|
}, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
};
|
||||||
|
|
||||||
generateFeed = function generateFeed(data) {
|
generateFeed = function generateFeed(data) {
|
||||||
var feed = new RSS({
|
var feed = new RSS({
|
||||||
title: data.title,
|
title: data.title,
|
||||||
|
@ -100,7 +114,7 @@ generateFeed = function generateFeed(data) {
|
||||||
guid: post.uuid,
|
guid: post.uuid,
|
||||||
url: itemUrl,
|
url: itemUrl,
|
||||||
date: post.published_at,
|
date: post.published_at,
|
||||||
categories: _.map(post.tags, 'name'),
|
categories: generateTags(post),
|
||||||
author: post.author ? post.author.name : null,
|
author: post.author ? post.author.name : null,
|
||||||
custom_elements: []
|
custom_elements: []
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,6 +4,7 @@ var should = require('should'),
|
||||||
_ = require('lodash'),
|
_ = require('lodash'),
|
||||||
Promise = require('bluebird'),
|
Promise = require('bluebird'),
|
||||||
testUtils = require('../utils'),
|
testUtils = require('../utils'),
|
||||||
|
labs = require('../../server/utils/labs'),
|
||||||
|
|
||||||
channelConfig = require('../../server/controllers/frontend/channel-config'),
|
channelConfig = require('../../server/controllers/frontend/channel-config'),
|
||||||
|
|
||||||
|
@ -147,6 +148,80 @@ describe('RSS', function () {
|
||||||
rss(req, res, failTest(done));
|
rss(req, res, failTest(done));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should only return visible tags if internal tags are enabled in labs', function (done) {
|
||||||
|
sandbox.stub(labs, 'isSet').returns(true);
|
||||||
|
var postWithTags = posts[2];
|
||||||
|
postWithTags.tags = [
|
||||||
|
{name: 'public', visibility: 'public'},
|
||||||
|
{name: 'internal', visibility: 'internal'},
|
||||||
|
{name: 'visibility'}
|
||||||
|
];
|
||||||
|
|
||||||
|
rss.__set__('getData', function () {
|
||||||
|
return Promise.resolve({
|
||||||
|
title: 'Test Title',
|
||||||
|
description: 'Testing Desc',
|
||||||
|
permalinks: '/:slug/',
|
||||||
|
results: {posts: [postWithTags], meta: {pagination: {pages: 1}}}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send = function send(xmlData) {
|
||||||
|
should.exist(xmlData);
|
||||||
|
// item tags
|
||||||
|
xmlData.should.match(/<title><!\[CDATA\[Short and Sweet\]\]>/);
|
||||||
|
xmlData.should.match(/<description><!\[CDATA\[test stuff/);
|
||||||
|
xmlData.should.match(/<content:encoded><!\[CDATA\[<h2 id="testing">testing<\/h2>\n\n/);
|
||||||
|
xmlData.should.match(/<img src="http:\/\/placekitten.com\/500\/200"/);
|
||||||
|
xmlData.should.match(/<media:content url="http:\/\/placekitten.com\/500\/200" medium="image"\/>/);
|
||||||
|
xmlData.should.match(/<category><!\[CDATA\[public\]\]/);
|
||||||
|
xmlData.should.match(/<category><!\[CDATA\[visibility\]\]/);
|
||||||
|
xmlData.should.not.match(/<category><!\[CDATA\[internal\]\]/);
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
|
req.channelConfig = channelConfig.get('index');
|
||||||
|
req.channelConfig.isRSS = true;
|
||||||
|
rss(req, res, failTest(done));
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return all tags if internal tags are not enabled in labs', function (done) {
|
||||||
|
sandbox.stub(labs, 'isSet').returns(false);
|
||||||
|
var postWithTags = posts[2];
|
||||||
|
postWithTags.tags = [
|
||||||
|
{name: 'public', visibility: 'public'},
|
||||||
|
{name: 'internal', visibility: 'internal'},
|
||||||
|
{name: 'visibility'}
|
||||||
|
];
|
||||||
|
|
||||||
|
rss.__set__('getData', function () {
|
||||||
|
return Promise.resolve({
|
||||||
|
title: 'Test Title',
|
||||||
|
description: 'Testing Desc',
|
||||||
|
permalinks: '/:slug/',
|
||||||
|
results: {posts: [postWithTags], meta: {pagination: {pages: 1}}}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
res.send = function send(xmlData) {
|
||||||
|
should.exist(xmlData);
|
||||||
|
// item tags
|
||||||
|
xmlData.should.match(/<title><!\[CDATA\[Short and Sweet\]\]>/);
|
||||||
|
xmlData.should.match(/<description><!\[CDATA\[test stuff/);
|
||||||
|
xmlData.should.match(/<content:encoded><!\[CDATA\[<h2 id="testing">testing<\/h2>\n\n/);
|
||||||
|
xmlData.should.match(/<img src="http:\/\/placekitten.com\/500\/200"/);
|
||||||
|
xmlData.should.match(/<media:content url="http:\/\/placekitten.com\/500\/200" medium="image"\/>/);
|
||||||
|
xmlData.should.match(/<category><!\[CDATA\[public\]\]/);
|
||||||
|
xmlData.should.match(/<category><!\[CDATA\[visibility\]\]/);
|
||||||
|
xmlData.should.match(/<category><!\[CDATA\[internal\]\]/);
|
||||||
|
done();
|
||||||
|
};
|
||||||
|
|
||||||
|
req.channelConfig = channelConfig.get('index');
|
||||||
|
req.channelConfig.isRSS = true;
|
||||||
|
rss(req, res, failTest(done));
|
||||||
|
});
|
||||||
|
|
||||||
it('should use meta_description and image where available', function (done) {
|
it('should use meta_description and image where available', function (done) {
|
||||||
rss.__set__('getData', function () {
|
rss.__set__('getData', function () {
|
||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
|
@ -167,7 +242,6 @@ describe('RSS', function () {
|
||||||
xmlData.should.match(/<img src="http:\/\/placekitten.com\/500\/200"/);
|
xmlData.should.match(/<img src="http:\/\/placekitten.com\/500\/200"/);
|
||||||
xmlData.should.match(/<media:content url="http:\/\/placekitten.com\/500\/200" medium="image"\/>/);
|
xmlData.should.match(/<media:content url="http:\/\/placekitten.com\/500\/200" medium="image"\/>/);
|
||||||
|
|
||||||
// done
|
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue