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

🐛 Fixed default theme context

closes #9674

- the collection router had a hardcoded default context "home"
  - this is wrong
- the context array get's automatically filled for the collection
  - if you are serving a page e.g. /page/2/ -> it's "paged"
  - if you are serving / -> it's "home"
    - same for {{body_class}}, it outputs "home-template" on "/"
    - this is the same behaviour as in 1.23.x
This commit is contained in:
kirrg001 2018-06-08 14:52:15 +02:00
parent 2d70b8fe20
commit e4807a779c
2 changed files with 28 additions and 1 deletions

View file

@ -90,7 +90,7 @@ class CollectionRouter extends ParentRouter {
filter: this.filter,
permalinks: this.permalinks.getValue({withUrlOptions: true}),
type: this.getType(),
context: ['home'],
context: [],
frontPageTemplate: 'home',
templates: this.templates,
identifier: this.identifier

View file

@ -7,6 +7,8 @@ const should = require('should'),
sandbox = sinon.sandbox.create();
describe('UNIT - services/routing/CollectionRouter', function () {
let req, res, next;
describe('instantiate', function () {
beforeEach(function () {
sandbox.stub(settingsCache, 'get').withArgs('permalinks').returns('/:slug/');
@ -16,6 +18,12 @@ describe('UNIT - services/routing/CollectionRouter', function () {
sandbox.spy(CollectionRouter.prototype, 'mountRoute');
sandbox.spy(CollectionRouter.prototype, 'mountRouter');
req = sandbox.stub();
res = sandbox.stub();
next = sandbox.stub();
res.locals = {};
});
afterEach(function () {
@ -117,6 +125,25 @@ describe('UNIT - services/routing/CollectionRouter', function () {
});
});
describe('fn: _prepareIndexContext', function () {
it('default', function () {
const collectionRouter = new CollectionRouter('/magic/', {permalink: '/:slug/', template: ['home', 'index']});
collectionRouter._prepareIndexContext(req, res, next);
next.calledOnce.should.be.true();
res.locals.routerOptions.should.eql({
filter: 'page:false',
permalinks: '/:slug/:options(edit)?/',
frontPageTemplate: 'home',
templates: ['index', 'home'],
identifier: collectionRouter.identifier,
context: [],
type: 'posts'
});
});
});
describe('permalink in database changes', function () {
beforeEach(function () {
sandbox.stub(settingsCache, 'get').withArgs('permalinks').returns('/:slug/');