mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
🐛 Fixed "Cannot read property 'feature_image' of undefined" (#10602)
no issue - refs https://forum.ghost.org/t/default-hbs-cannot-read-property-feature-image-of-undefined/6194 -
This commit is contained in:
parent
7bac1824c2
commit
f64af762ef
4 changed files with 51 additions and 4 deletions
|
@ -16,14 +16,19 @@ function getContextObject(data, context) {
|
|||
// @TODO: meta layer is very broken, it's really hard to understand what it's doing
|
||||
// The problem is that handlebars root object is structured differently. Sometimes the object is flat on data
|
||||
// and sometimes the object is part of a key e.g. data.post. This needs to be prepared at the very first stage and not in each helper.
|
||||
if (_.includes(context, 'page') || _.includes(context, 'amp') && data.post) {
|
||||
if ((_.includes(context, 'page') || _.includes(context, 'amp')) && data.post) {
|
||||
chosenContext = data.post;
|
||||
} else if (_.includes(context, 'post') && data.post) {
|
||||
chosenContext = data.post;
|
||||
} else if (_.includes(context, 'page') && data.page) {
|
||||
chosenContext = data.page;
|
||||
} else if (data[context]) {
|
||||
// @NOTE: This is confusing as hell. It tries to get data[['author']], which works, but coincidence?
|
||||
chosenContext = data[context];
|
||||
} else {
|
||||
}
|
||||
|
||||
// Super fallback.
|
||||
if (!chosenContext) {
|
||||
chosenContext = blog;
|
||||
}
|
||||
|
||||
|
|
|
@ -2625,10 +2625,28 @@ describe('Integration - Web - Site', function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe('collection with data key', function () {
|
||||
describe('collection/routes with data key', function () {
|
||||
before(function () {
|
||||
sinon.stub(settingsService, 'get').returns({
|
||||
routes: {},
|
||||
routes: {
|
||||
'/my-page/': {
|
||||
data: {
|
||||
query: {
|
||||
page: {
|
||||
controller: 'pagesPublic',
|
||||
resource: 'pages',
|
||||
type: 'read',
|
||||
options: {
|
||||
slug: 'static-page-test'
|
||||
}
|
||||
}
|
||||
},
|
||||
router: {
|
||||
pages: [{redirect: true, slug: 'static-page-test'}]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
collections: {
|
||||
'/food/': {
|
||||
|
@ -2759,6 +2777,20 @@ describe('Integration - Web - Site', function () {
|
|||
response.statusCode.should.eql(200);
|
||||
});
|
||||
});
|
||||
|
||||
it('serve my-page', function () {
|
||||
const req = {
|
||||
secure: true,
|
||||
method: 'GET',
|
||||
url: '/my-page/',
|
||||
host: 'example.com'
|
||||
};
|
||||
|
||||
return testUtils.mocks.express.invoke(app, req)
|
||||
.then(function (response) {
|
||||
response.statusCode.should.eql(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -46,6 +46,15 @@ describe('getContextObject', function () {
|
|||
contextObject.should.eql(data.post);
|
||||
});
|
||||
|
||||
it('should return page', function () {
|
||||
data = {page: {id: 2}};
|
||||
context = ['news', 'page'];
|
||||
contextObject = getContextObject(data, context);
|
||||
|
||||
should.exist(contextObject);
|
||||
contextObject.should.eql(data.page);
|
||||
});
|
||||
|
||||
describe('override blog', function () {
|
||||
before(function () {
|
||||
sinon.stub(settingsCache, 'get').callsFake(function (key) {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{{ghost_head}}
|
Loading…
Reference in a new issue