mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-13 22:41:32 -05:00
Merge pull request #4093 from halfdan/update-helpers
Update meta_* helpers.
This commit is contained in:
commit
792e748e2f
2 changed files with 26 additions and 10 deletions
|
@ -296,12 +296,6 @@ coreHelpers.content = function (options) {
|
|||
);
|
||||
}
|
||||
|
||||
// Due to weirdness in downsize the 'words' option
|
||||
// must be passed as a string. refer to #1796
|
||||
// TODO: when downsize fixes this quirk remove this hack.
|
||||
if (truncateOptions.hasOwnProperty('words')) {
|
||||
truncateOptions.words = truncateOptions.words.toString();
|
||||
}
|
||||
return new hbs.handlebars.SafeString(
|
||||
downsize(this.html, truncateOptions)
|
||||
);
|
||||
|
@ -573,7 +567,7 @@ coreHelpers.meta_title = function (options) {
|
|||
} else if (this.tag) {
|
||||
title = this.tag.name + pageString + ' - ' + blog.title;
|
||||
} else if (this.post) {
|
||||
title = this.post.title;
|
||||
title = _.isEmpty(this.post.meta_title) ? this.post.title : this.post.meta_title;
|
||||
} else {
|
||||
title = blog.title + pageString;
|
||||
}
|
||||
|
@ -595,8 +589,10 @@ coreHelpers.meta_description = function (options) {
|
|||
description = blog.description;
|
||||
} else if (this.author) {
|
||||
description = /\/page\//.test(this.relativeUrl) ? '' : this.author.bio;
|
||||
} else if (this.tag || this.post || /\/page\//.test(this.relativeUrl)) {
|
||||
} else if (this.tag || /\/page\//.test(this.relativeUrl)) {
|
||||
description = '';
|
||||
} else if (this.post) {
|
||||
description = _.isEmpty(this.post.meta_description) ? '' : this.post.meta_description;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1239,6 +1239,16 @@ describe('Core Helpers', function () {
|
|||
}).catch(done);
|
||||
});
|
||||
|
||||
it('returns correct title for a post with meta_title set', function (done) {
|
||||
var post = {relativeUrl: '/nice-post', post: {title: 'Post Title', meta_title: 'Awesome Post'}};
|
||||
helpers.meta_title.call(post).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('Awesome Post');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('returns correct title for a tag page', function (done) {
|
||||
var tag = {relativeUrl: '/tag/rasper-red', tag: {name: 'Rasper Red'}};
|
||||
helpers.meta_title.call(tag).then(function (rendered) {
|
||||
|
@ -1353,8 +1363,8 @@ describe('Core Helpers', function () {
|
|||
}).catch(done);
|
||||
});
|
||||
|
||||
it('returns empty description on post', function (done) {
|
||||
var post = {relativeUrl: '/nice-post', post: {title: 'Post Title'}};
|
||||
it('returns empty description when meta_description is not set', function (done) {
|
||||
var post = {relativeUrl: '/nice-post', post: {title: 'Post Title', html: 'Very nice post indeed.'}};
|
||||
helpers.meta_description.call(post).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('');
|
||||
|
@ -1362,6 +1372,16 @@ describe('Core Helpers', function () {
|
|||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('returns meta_description on post with meta_description set', function (done) {
|
||||
var post = {relativeUrl: '/nice-post', post: {title: 'Post Title', meta_description: 'Nice post about stuff.'}};
|
||||
helpers.meta_description.call(post).then(function (rendered) {
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('Nice post about stuff.');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('asset helper', function () {
|
||||
|
|
Loading…
Reference in a new issue