0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

🦄 Channels: make RSS & Pagination configurable (#8857)

refs #5091

- occurred to me whilst documenting the custom homepage config, that RSS and pagination
need to be optional
- added a very quick if statement & tests
- needs further refactoring & test improvements
- this will not disable the RSS url output in meta data yet 😔
This commit is contained in:
Hannah Wolfe 2017-08-10 10:12:09 +01:00 committed by Katharina Irrgang
parent 147ec91162
commit 1cc4be8010
3 changed files with 110 additions and 7 deletions

View file

@ -72,9 +72,17 @@ channelRouter = function router() {
// @TODO figure out how to collapse this into a single rule
channelRouter.get(baseRoute, configChannel, renderChannel);
channelRouter.get(pageRoute, configChannel, renderChannel);
channelRouter.param('page', handlePageParam);
channelRouter.use(rssRouter(configChannel));
// @TODO improve config and add defaults to make this simpler
if (channel.paged !== false) {
channelRouter.param('page', handlePageParam);
channelRouter.get(pageRoute, configChannel, renderChannel);
}
// @TODO improve config and add defaults to make this simpler
if (channel.rss !== false) {
channelRouter.use(rssRouter(configChannel));
}
if (channel.editRedirect) {
channelRouter.get('/edit/', function redirect(req, res) {

View file

@ -1,22 +1,22 @@
/*jshint expr:true*/
var should = require('should'),
channelConfig = require('../../../../server/controllers/frontend/channel-config').get;
channelConfig = require('../../../../server/controllers/frontend/channel-config');
describe('Channel Config', function () {
it('should get the index config', function () {
var result = channelConfig('index');
var result = channelConfig.get('index');
should.exist(result);
result.name.should.eql('index');
});
it('should get the author config', function () {
var result = channelConfig('author');
var result = channelConfig.get('author');
should.exist(result);
result.name.should.eql('author');
});
it('should get the tag config', function () {
var result = channelConfig('tag');
var result = channelConfig.get('tag');
should.exist(result);
result.name.should.eql('tag');
});

View file

@ -0,0 +1,95 @@
var should = require('should'), // jshint ignore:line
sinon = require('sinon'),
// Stuff we are testing
channelConfig = require('../../../../server/controllers/frontend/channel-config'),
channels = require('../../../../server/controllers/frontend/channels'),
sandbox = sinon.sandbox.create();
/**
* These tests are a bit weird,
* need to test express private API
* Would be better to be testing our own internal API
* E.g. setupRSS.calledOnce, rather than router stack!
*/
describe('Custom Channels', function () {
afterEach(function () {
sandbox.restore();
});
it('allows basic custom config', function () {
sandbox.stub(channelConfig, 'list').returns({
home: {
name: 'home',
route: '/home/'
}
});
var channelRouter = channels.router(),
topRouter = channelRouter.stack[0],
routeStack = topRouter.handle.stack,
rssRouter = routeStack[2].handle.stack;
topRouter.regexp.toString().should.match(/\\\/home\\\//);
routeStack.should.have.lengthOf(3);
// Route 1 should be /
routeStack[0].route.path.should.eql('/');
// Route 2 should be pagination
routeStack[1].route.path.should.eql('/page/:page(\\d+)/');
// Route 3 should be a whole new router for RSS
rssRouter.should.have.lengthOf(3);
rssRouter[0].route.path.should.eql('/rss/');
rssRouter[1].route.path.should.eql('/rss/:page(\\d+)/');
rssRouter[2].route.path.should.eql('/feed/');
});
it('allows rss to be disabled', function () {
sandbox.stub(channelConfig, 'list').returns({
home: {
name: 'home',
route: '/home/',
rss: false
}
});
var channelRouter = channels.router(),
topRouter = channelRouter.stack[0],
routeStack = topRouter.handle.stack;
topRouter.regexp.toString().should.match(/\\\/home\\\//);
routeStack.should.have.lengthOf(2);
// Route 1 should be /
routeStack[0].route.path.should.eql('/');
// Route 2 should be pagination
routeStack[1].route.path.should.eql('/page/:page(\\d+)/');
});
it('allows pagination to be disabled', function () {
sandbox.stub(channelConfig, 'list').returns({
home: {
name: 'home',
route: '/home/',
paged: false
}
});
var channelRouter = channels.router(),
topRouter = channelRouter.stack[0],
routeStack = topRouter.handle.stack,
rssRouter = routeStack[1].handle.stack;
topRouter.regexp.toString().should.match(/\\\/home\\\//);
routeStack.should.have.lengthOf(2);
// Route 1 should be /
routeStack[0].route.path.should.eql('/');
// Route 2 should be a whole new router for RSS
rssRouter.should.have.lengthOf(3);
rssRouter[0].route.path.should.eql('/rss/');
rssRouter[1].route.path.should.eql('/rss/:page(\\d+)/');
rssRouter[2].route.path.should.eql('/feed/');
});
});