🐛 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:
kirrg001 2019-03-12 01:16:02 +01:00 committed by Katharina Irrgang
parent fef0aa44d3
commit 3b4edccf62
3 changed files with 32 additions and 2 deletions

View File

@ -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();

View File

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

View File

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