mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 18:31:57 +03:00
10fc320cc8
no issue - In Ghost, 'context' means the page or section of a blog we're currently within when rendering a theme, e.g. 'post' or 'tag' or 'home'. - In handlebars 'context' refers to the blob of JSON that is tied to a template. - These two uses of the word 'context' have gotten very confusing, so I've removed all usage of 'context' within the Ghost handlebars helpers, EXCEPT where they actually refer to the current context (e.g. the is helper)
42 lines
1.2 KiB
JavaScript
42 lines
1.2 KiB
JavaScript
// # Author Helper
|
|
// Usage: `{{author}}` OR `{{#author}}{{/author}}`
|
|
//
|
|
// Can be used as either an output or a block helper
|
|
//
|
|
// Output helper: `{{author}}`
|
|
// Returns the full name of the author of a given post, or a blank string
|
|
// if the author could not be determined.
|
|
//
|
|
// Block helper: `{{#author}}{{/author}}`
|
|
// This is the default handlebars behaviour of dropping into the author object scope
|
|
|
|
var hbs = require('express-hbs'),
|
|
_ = require('lodash'),
|
|
config = require('../config'),
|
|
utils = require('./utils'),
|
|
author;
|
|
|
|
author = function (options) {
|
|
if (options.fn) {
|
|
return hbs.handlebars.helpers.with.call(this, this.author, options);
|
|
}
|
|
|
|
var autolink = _.isString(options.hash.autolink) && options.hash.autolink === 'false' ? false : true,
|
|
output = '';
|
|
|
|
if (this.author && this.author.name) {
|
|
if (autolink) {
|
|
output = utils.linkTemplate({
|
|
url: config.urlFor('author', {author: this.author}),
|
|
text: _.escape(this.author.name)
|
|
});
|
|
} else {
|
|
output = _.escape(this.author.name);
|
|
}
|
|
}
|
|
|
|
return new hbs.handlebars.SafeString(output);
|
|
};
|
|
|
|
module.exports = author;
|