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

🐛 Fixed {{#is "index"}}

closes https://github.com/TryGhost/Ghost/issues/9674

- with dynamic routing the first collection get's the "index" context attached
- the index context signalises the main post listening route (first collection)
- this behaviour was present < 1.24 - we have to keep this behaviour
This commit is contained in:
kirrg001 2018-06-14 11:53:13 +02:00
parent e99fb78b66
commit 87c01c131b
4 changed files with 29 additions and 4 deletions

View file

@ -9,9 +9,13 @@ const middlewares = require('./middlewares');
const RSSRouter = require('./RSSRouter');
class CollectionRouter extends ParentRouter {
constructor(indexRoute, object) {
constructor(indexRoute, object, options) {
options = options || {};
super('CollectionRouter');
this.firstCollection = options.firstCollection;
// NOTE: index/parent route e.g. /, /podcast/, /magic/ ;)
this.route = {
value: indexRoute
@ -48,6 +52,13 @@ class CollectionRouter extends ParentRouter {
return this.permalinks.value;
};
// the main post listening collection get's the index context
if (this.firstCollection) {
this.context = ['index'];
} else {
this.context = [];
}
debug(this.route, this.permalinks);
this._registerRoutes();
@ -90,7 +101,7 @@ class CollectionRouter extends ParentRouter {
filter: this.filter,
permalinks: this.permalinks.getValue({withUrlOptions: true}),
type: this.getType(),
context: [],
context: this.context,
frontPageTemplate: 'home',
templates: this.templates,
identifier: this.identifier

View file

@ -47,7 +47,10 @@ module.exports = function bootstrap() {
});
_.each(dynamicRoutes.collections, (value, key) => {
const collectionRouter = new CollectionRouter(key, value);
const collectionRouter = new CollectionRouter(key, value, {
firstCollection: Object.keys(dynamicRoutes.collections).indexOf(key) === 0
});
siteRouter.mountRouter(collectionRouter.router());
registry.setRouter(collectionRouter.identifier, collectionRouter);

View file

@ -21,7 +21,7 @@ module.exports = {
getFirstCollectionRouter() {
return _.find(routers, (router) => {
if (router.name === 'CollectionRouter') {
if (router.name === 'CollectionRouter' && router.firstCollection) {
return router;
}

View file

@ -64,6 +64,17 @@ describe('UNIT - services/routing/CollectionRouter', function () {
collectionRouter.mountRouter.args[0][1].should.eql(collectionRouter.rssRouter.router());
});
it('first collection option', function () {
const collectionRouter1 = new CollectionRouter('/', {permalink: '/:slug/'}, {firstCollection: true});
const collectionRouter2 = new CollectionRouter('/', {permalink: '/:slug/'}, {firstCollection: false});
collectionRouter1.firstCollection.should.be.true();
collectionRouter2.firstCollection.should.be.false();
collectionRouter1.context.should.eql(['index']);
collectionRouter2.context.should.eql([]);
});
it('collection lives under /blog/', function () {
const collectionRouter = new CollectionRouter('/blog/', {permalink: '/blog/:year/:slug/'});