From f25f7ac54b9707aea24cf97e7a3e91141e10a7fa Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Mon, 11 Jun 2018 22:06:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20slug=20template=20for=20?= =?UTF-8?q?tags=20and=20authors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no issue - was introduced with dynamic routing beta: https://github.com/TryGhost/Ghost/releases/tag/1.24.0 - the slug param wasn't forwarded correctly - you were not able to render a custom tag or author template e.g. `tag-news.hbs` --- .../services/routing/helpers/templates.js | 7 ++++--- .../services/routing/helpers/templates_spec.js | 18 ++++++++---------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/core/server/services/routing/helpers/templates.js b/core/server/services/routing/helpers/templates.js index 387e5d08a4..c0c487bdd3 100644 --- a/core/server/services/routing/helpers/templates.js +++ b/core/server/services/routing/helpers/templates.js @@ -52,8 +52,8 @@ _private.getCollectionTemplateHierarchy = function getCollectionTemplateHierarch if (routerOptions.name && routerOptions.name !== 'index') { templateList.unshift(routerOptions.name); - if (routerOptions.slugTemplate && routerOptions.slugParam) { - templateList.unshift(routerOptions.name + '-' + routerOptions.slugParam); + if (routerOptions.slugTemplate && requestOptions.slugParam) { + templateList.unshift(routerOptions.name + '-' + requestOptions.slugParam); } } @@ -176,7 +176,8 @@ module.exports.setTemplate = function setTemplate(req, res, data) { case 'collection': res._template = _private.getTemplateForCollection(res.locals.routerOptions, { path: url.parse(req.url).pathname, - page: req.params.page + page: req.params.page, + slugParam: req.params.slug }); break; case 'entry': diff --git a/core/test/unit/services/routing/helpers/templates_spec.js b/core/test/unit/services/routing/helpers/templates_spec.js index 4bfeb9cb7a..43c1176ad7 100644 --- a/core/test/unit/services/routing/helpers/templates_spec.js +++ b/core/test/unit/services/routing/helpers/templates_spec.js @@ -23,7 +23,7 @@ describe('templates', function () { }); it('should return just index if collection name is index even if slug is set', function () { - _private.getCollectionTemplateHierarchy({name: 'index', slugTemplate: true, slugParam: 'test'}).should.eql(['index']); + _private.getCollectionTemplateHierarchy({name: 'index', slugTemplate: true}, {slugParam: 'test'}).should.eql(['index']); }); it('should return collection, index if collection has name', function () { @@ -33,18 +33,16 @@ describe('templates', function () { it('should return collection-slug, collection, index if collection has name & slug + slugTemplate set', function () { _private.getCollectionTemplateHierarchy({ name: 'tag', - slugTemplate: true, - slugParam: 'test' - }).should.eql(['tag-test', 'tag', 'index']); + slugTemplate: true + }, {slugParam: 'test'}).should.eql(['tag-test', 'tag', 'index']); }); it('should return front, collection-slug, collection, index if name, slugParam+slugTemplate & frontPageTemplate+pageParam=1 is set', function () { _private.getCollectionTemplateHierarchy({ name: 'tag', slugTemplate: true, - slugParam: 'test', frontPageTemplate: 'front-tag' - }, {page: 1, path: '/'}).should.eql(['front-tag', 'tag-test', 'tag', 'index']); + }, {page: 1, path: '/', slugParam: 'test'}).should.eql(['front-tag', 'tag-test', 'tag', 'index']); }); it('should return home, index for index collection if front is set and pageParam = 1', function () { @@ -260,7 +258,7 @@ describe('templates', function () { }); it('will return correct view for a tag', function () { - var view = _private.getTemplateForCollection({name: 'tag', slugParam: 'development', slugTemplate: true}); + var view = _private.getTemplateForCollection({name: 'tag', slugTemplate: true}, {slugParam: 'development'}); should.exist(view); view.should.eql('index'); }); @@ -275,20 +273,20 @@ describe('templates', function () { }); it('will return correct view for a tag', function () { - var view = _private.getTemplateForCollection({name: 'tag', slugParam: 'design', slugTemplate: true}); + var view = _private.getTemplateForCollection({name: 'tag', slugTemplate: true}, {slugParam: 'design'}); should.exist(view); view.should.eql('tag-design'); }); it('will return correct view for a tag', function () { - var view = _private.getTemplateForCollection({name: 'tag', slugParam: 'development', slugTemplate: true}); + var view = _private.getTemplateForCollection({name: 'tag', slugTemplate: true}, {slugParam: 'development'}); should.exist(view); view.should.eql('tag'); }); }); it('will fall back to index even if no index.hbs', function () { - var view = _private.getTemplateForCollection({name: 'tag', slugParam: 'development', slugTemplate: true}); + var view = _private.getTemplateForCollection({name: 'tag', slugTemplate: true}, {slugParam: 'development'}); should.exist(view); view.should.eql('index'); });