mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 05:37:34 +03:00
🐛 Fixed {{meta_description}} output when using data: page.{slug}
in routes
refs #10599 - meta_description output wrong meta description Only solves meta_description for this use case: ``` routes: /: data: page.{slug} template: t ```
This commit is contained in:
parent
fef0aa44d3
commit
3b4edccf62
@ -24,13 +24,28 @@ function getDescription(data, root, options) {
|
||||
description = data.author.meta_description || '';
|
||||
} else if (_.includes(context, 'tag') && data.tag) {
|
||||
description = data.tag.meta_description || '';
|
||||
} else if ((_.includes(context, 'post') || _.includes(context, 'page')) && data.post) {
|
||||
} else if (_.includes(context, 'post') && data.post) {
|
||||
if (options && options.property) {
|
||||
postSdDescription = options.property + '_description';
|
||||
description = data.post[postSdDescription] || '';
|
||||
} else {
|
||||
description = data.post.meta_description || '';
|
||||
}
|
||||
} else if (_.includes(context, 'page') && data.post) {
|
||||
// @NOTE: v0.1
|
||||
if (options && options.property) {
|
||||
postSdDescription = options.property + '_description';
|
||||
description = data.post[postSdDescription] || '';
|
||||
} else {
|
||||
description = data.post.meta_description || '';
|
||||
}
|
||||
} else if (_.includes(context, 'page') && data.page) {
|
||||
if (options && options.property) {
|
||||
postSdDescription = options.property + '_description';
|
||||
description = data.page[postSdDescription] || '';
|
||||
} else {
|
||||
description = data.page.meta_description || '';
|
||||
}
|
||||
}
|
||||
|
||||
return (description || '').trim();
|
||||
|
@ -71,6 +71,10 @@ function setResponseContext(req, res, data) {
|
||||
if (!res.locals.context.includes('post')) {
|
||||
res.locals.context.push('post');
|
||||
}
|
||||
} else if (data && data.page) {
|
||||
if (!res.locals.context.includes('page')) {
|
||||
res.locals.context.push('page');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,7 +126,7 @@ describe('getMetaDescription', function () {
|
||||
description.should.equal('Best AMP post ever!');
|
||||
});
|
||||
|
||||
it('should return data post meta description if on root context contains page', function () {
|
||||
it('v0.1: should return data post meta description if on root context contains page', function () {
|
||||
var description = getMetaDescription({
|
||||
post: {
|
||||
meta_description: 'Best page ever!'
|
||||
@ -136,4 +136,15 @@ describe('getMetaDescription', function () {
|
||||
});
|
||||
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: {
|
||||
meta_description: 'Best page ever!'
|
||||
}
|
||||
}, {
|
||||
context: ['page']
|
||||
});
|
||||
description.should.equal('Best page ever!');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user