0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

Update meta_* helpers.

no ref
- Return meta_description from post.meta_description if set
- Return meta_title either from post.title or post.meta_title if set
- Adds tests
This commit is contained in:
Fabian Becker 2014-09-22 13:02:58 +00:00
parent 438444df3d
commit 801c5248c2
2 changed files with 26 additions and 10 deletions

View file

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

View file

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