From ae5eb4802c442581ad3e1d49a6e424f96c2aaad9 Mon Sep 17 00:00:00 2001 From: Nazar Gargol Date: Mon, 11 Nov 2019 17:36:00 +0700 Subject: [PATCH] Reverted support to only `data.post` in meta layer no issue - It was partially removed in https://github.com/TryGhost/Ghost/pull/11080/files but didn't take into account hardcoded value in format response stage --- core/frontend/meta/description.js | 2 +- core/frontend/meta/index.js | 10 +++++----- core/test/unit/data/meta/description_spec.js | 12 ++++++++++++ core/test/unit/data/meta/title_spec.js | 13 ++++++++++++- core/test/unit/helpers/ghost_head_spec.js | 4 ++-- 5 files changed, 32 insertions(+), 9 deletions(-) diff --git a/core/frontend/meta/description.js b/core/frontend/meta/description.js index bcc073d95e..3b98590e63 100644 --- a/core/frontend/meta/description.js +++ b/core/frontend/meta/description.js @@ -37,7 +37,7 @@ function getDescription(data, root, options) { description = data.post.meta_description || ''; } } else if (_.includes(context, 'page') && data.post) { - // @NOTE: + // Page title dependent on legacy object formatting (https://github.com/TryGhost/Ghost/issues/10042) if (options && options.property) { postSdDescription = options.property + '_description'; description = data.post[postSdDescription] || ''; diff --git a/core/frontend/meta/index.js b/core/frontend/meta/index.js index d99f8c4f7f..c04a5895a6 100644 --- a/core/frontend/meta/index.js +++ b/core/frontend/meta/index.js @@ -77,17 +77,17 @@ function getMetaData(data, root) { fallbackExcerpt; // TODO: cleanup these if statements - if (data.post || data.page) { + // NOTE: should use 'post' OR 'page' once https://github.com/TryGhost/Ghost/issues/10042 is resolved + if (data.post) { // There's a specific order for description fields (not !!) in structured data // and schema.org which is used the description fields (see https://github.com/TryGhost/Ghost/issues/8793): // 1. CASE: custom_excerpt is populated via the UI // 2. CASE: no custom_excerpt, but meta_description is poplated via the UI // 3. CASE: fall back to automated excerpt of 50 words if neither custom_excerpt nor meta_description is provided // @TODO: https://github.com/TryGhost/Ghost/issues/10062 - const prop = data.post ? 'post' : 'page'; - customExcerpt = data[prop].excerpt || data[prop].custom_excerpt; - metaDescription = data[prop].meta_description; - fallbackExcerpt = data[prop].html ? getExcerpt(data[prop].html, {words: 50}) : ''; + customExcerpt = data.post.excerpt || data.post.custom_excerpt; + metaDescription = data.post.meta_description; + fallbackExcerpt = data.post.html ? getExcerpt(data.post.html, {words: 50}) : ''; metaData.excerpt = customExcerpt ? customExcerpt : metaDescription ? metaDescription : fallbackExcerpt; } diff --git a/core/test/unit/data/meta/description_spec.js b/core/test/unit/data/meta/description_spec.js index 463b0394ea..0ceefafb14 100644 --- a/core/test/unit/data/meta/description_spec.js +++ b/core/test/unit/data/meta/description_spec.js @@ -189,6 +189,18 @@ describe('getMetaDescription', function () { description.should.equal('Best AMP post ever!'); }); + // NOTE: this is a legacy format and should be resolved with https://github.com/TryGhost/Ghost/issues/10042 + it('legacy: should return data post meta description if on root context contains page', function () { + var description = getMetaDescription({ + post: { + meta_description: 'Best page ever!' + } + }, { + context: ['page'] + }); + description.should.equal('Best page ever!'); + }); + it('v2: should return data page meta description if on root context contains page', function () { var description = getMetaDescription({ page: { diff --git a/core/test/unit/data/meta/title_spec.js b/core/test/unit/data/meta/title_spec.js index 5d8a8dfc1b..6ba0053239 100644 --- a/core/test/unit/data/meta/title_spec.js +++ b/core/test/unit/data/meta/title_spec.js @@ -128,6 +128,17 @@ describe('getTitle', function () { title.should.equal('Tag Name - My site title 3 (Page 39)'); }); + it('should return post title if in page context', function () { + var title = getTitle({ + // 'post' property is dependent on legacy object formatting (https://github.com/TryGhost/Ghost/issues/10042 + post: { + title: 'My awesome page!' + } + }, {context: ['page']}); + + title.should.equal('My awesome page!'); + }); + it('should return translated pagination-string if passed in options object', function () { localSettingsCache.title = 'This is my site title'; @@ -259,7 +270,7 @@ describe('getTitle', function () { // NOTE: this case is unlikely as Ghost doesn't support AMP for static pages it('should return post title if in amp and page context', function () { var title = getTitle({ - page: { + post: { title: 'My awesome page!' } }, {context: ['amp', 'page']}); diff --git a/core/test/unit/helpers/ghost_head_spec.js b/core/test/unit/helpers/ghost_head_spec.js index 88aafd3257..89cb4cf747 100644 --- a/core/test/unit/helpers/ghost_head_spec.js +++ b/core/test/unit/helpers/ghost_head_spec.js @@ -420,7 +420,7 @@ describe('{{ghost_head}} helper', function () { it('returns structured data on static page', function (done) { var renderObject = { - page: posts[0] + post: posts[0] }; helpers.ghost_head(testUtils.createHbsResponse({ @@ -469,7 +469,7 @@ describe('{{ghost_head}} helper', function () { it('returns structured data on static page with custom post structured data', function (done) { var renderObject = { - page: posts[1] + post: posts[1] }; helpers.ghost_head(testUtils.createHbsResponse({