From 555dc2f180629d25aaba9c18f2b7d9a5950b5d30 Mon Sep 17 00:00:00 2001 From: kirrg001 Date: Tue, 12 Mar 2019 01:17:27 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20{{meta=5Ftitle}}=20outpu?= =?UTF-8?q?t=20when=20using=20`data:=20page.{slug}`=20in=20routes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs #10082 - meta_title output wrong meta title Only solves meta_title outout for this use case: ``` routes: /: data: page.{slug} template: t ``` --- core/server/data/meta/title.js | 18 +++++++++++++++++- core/test/unit/data/meta/title_spec.js | 12 +++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/core/server/data/meta/title.js b/core/server/data/meta/title.js index 600d37e8cf..49ac163e51 100644 --- a/core/server/data/meta/title.js +++ b/core/server/data/meta/title.js @@ -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; diff --git a/core/test/unit/data/meta/title_spec.js b/core/test/unit/data/meta/title_spec.js index da931ece9f..36245db240 100644 --- a/core/test/unit/data/meta/title_spec.js +++ b/core/test/unit/data/meta/title_spec.js @@ -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: {