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

🐛 Fixed slug template for tags and authors

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`
This commit is contained in:
kirrg001 2018-06-11 22:06:47 +02:00
parent 0dd619b688
commit f25f7ac54b
2 changed files with 12 additions and 13 deletions

View file

@ -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':

View file

@ -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');
});