Skip to content

Commit

Permalink
🐛 Fixed {{meta_title}} output when using data: page.{slug} in routes
Browse files Browse the repository at this point in the history
refs TryGhost#10082

- meta_title output wrong meta title

Only solves meta_title outout for this use case:

```
routes:
  /:
    data: page.{slug}
    template: t
```
  • Loading branch information
kirrg001 committed Mar 12, 2019
1 parent b79998b commit fdb77f9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 17 additions & 1 deletion core/server/data/meta/title.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion core/test/unit/data/meta/title_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!'
Expand All @@ -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: {
Expand Down

0 comments on commit fdb77f9

Please sign in to comment.