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

🐛 Fixed {{meta_title}} output when using data: page.{slug} in routes

refs #10082

- meta_title output wrong meta title

Only solves meta_title outout for this use case:

```
routes:
  /:
    data: page.{slug}
    template: t
```
This commit is contained in:
kirrg001 2019-03-12 01:17:27 +01:00 committed by Katharina Irrgang
parent 3b4edccf62
commit 555dc2f180
2 changed files with 28 additions and 2 deletions

View file

@ -34,13 +34,29 @@ function getTitle(data, root, options) {
} else if (_.includes(context, 'tag') && data.tag) {
title = data.tag.meta_title || data.tag.name + ' - ' + blogTitle;
// Post title
} else if ((_.includes(context, 'post') || _.includes(context, 'page')) && data.post) {
} else if (_.includes(context, 'post') && data.post) {
if (options && options.property) {
postSdTitle = options.property + '_title';
title = data.post[postSdTitle] || '';
} else {
title = data.post.meta_title || data.post.title;
}
// Page title v0.1
} else if (_.includes(context, 'page') && data.post) {
if (options && options.property) {
postSdTitle = options.property + '_title';
title = data.post[postSdTitle] || '';
} else {
title = data.post.meta_title || data.post.title;
}
// Page title v2
} else if (_.includes(context, 'page') && data.page) {
if (options && options.property) {
postSdTitle = options.property + '_title';
title = data.page[postSdTitle] || '';
} else {
title = data.page.meta_title || data.page.title;
}
// Fallback
} else {
title = blogTitle + pageString;

View file

@ -190,7 +190,7 @@ describe('getTitle', function () {
title.should.equal('My awesome post!');
});
it('should return post title if in page context', function () {
it('v0.1: should return post title if in page context', function () {
var title = getTitle({
post: {
title: 'My awesome page!'
@ -200,6 +200,16 @@ describe('getTitle', function () {
title.should.equal('My awesome page!');
});
it('v2: should return page title if in page context', function () {
var title = getTitle({
page: {
title: 'My awesome page!'
}
}, {context: ['page']});
title.should.equal('My awesome page!');
});
it('should return post title if in amp and page context', function () {
var title = getTitle({
post: {