0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Added support for custom channel contexts (#9114)

refs #5091

- This simple change allows custom contexts to use existing channel logic
- E.g. if we want to create a custom tag-based channel, it can pass "tag" as the context, and get all the same metadata logic
This commit is contained in:
Hannah Wolfe 2017-10-09 10:59:46 +01:00 committed by Katharina Irrgang
parent e6779d4cdc
commit 75fdcd168e
2 changed files with 22 additions and 1 deletions

View file

@ -54,7 +54,11 @@ function setResponseContext(req, res, data) {
// Each page can only have at most one of these
if (res.locals.channel) {
if (res.locals.channel.context) {
res.locals.context = res.locals.context.concat(res.locals.channel.context);
} else {
res.locals.context.push(res.locals.channel.name);
}
} else if (privatePattern.test(res.locals.relativeUrl)) {
res.locals.context.push('private');
} else if (subscribePattern.test(res.locals.relativeUrl) && labs.isSet('subscribers') === true) {

View file

@ -273,6 +273,23 @@ describe('Contexts', function () {
res.locals.context[0].should.eql('featured');
});
it('will use a custom context for a custom channel', function () {
var channel = _.clone(featuredChannel);
channel.context = ['custom-context', 'test'];
// Setup test
setupContext('/featured/', channel);
// Execute test
setResponseContext(req, res, data);
// Check context
should.exist(res.locals.context);
res.locals.context.should.be.an.Array().with.lengthOf(2);
res.locals.context[0].should.eql('custom-context');
res.locals.context[1].should.eql('test');
});
it('will not identify /page/2/ as paged without page param', function () {
// Setup test
setupContext('/featured/page/2/', featuredChannel);