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
This commit is contained in:
Nazar Gargol 2019-11-11 17:36:00 +07:00
parent 6345684556
commit ae5eb4802c
5 changed files with 32 additions and 9 deletions

View File

@ -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] || '';

View File

@ -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 <meta name="description" /> !!) 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;
}

View File

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

View File

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

View File

@ -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({