2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00
Ghost/core/server/helpers/author.js
Katharina Irrgang 40d0a745df Multiple authors (#9426)
no issue

This PR adds the server side logic for multiple authors. This adds the ability to add multiple authors per post. We keep and support single authors (maybe till the next major - this is still in discussion)

### key notes

- `authors` are not fetched by default, only if we need them
- the migration script iterates over all posts and figures out if an author_id is valid and exists (in master we can add invalid author_id's) and then adds the relation (falls back to owner if invalid)
- ~~i had to push a fork of bookshelf to npm because we currently can't bump bookshelf + the two bugs i discovered are anyway not yet merged (https://github.com/kirrg001/bookshelf/commits/master)~~ replaced by new bookshelf release
- the implementation of single & multiple authors lives in a single place (introduction of a new concept: model relation)
- if you destroy an author, we keep the behaviour for now -> remove all posts where the primary author id matches. furthermore, remove all relations in posts_authors (e.g. secondary author)
- we make re-use of the `excludeAttrs` concept which was invented in the contributors PR (to protect editing authors as author/contributor role) -> i've added a clear todo that we need a logic to make a diff of the target relation -> both for tags and authors
- `authors` helper available (same as `tags` helper)
- `primary_author` computed field available
- `primary_author` functionality available (same as `primary_tag` e.g. permalinks, prev/next helper etc)
2018-03-27 15:16:15 +01:00

43 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 proxy = require('./proxy'),
_ = require('lodash'),
SafeString = proxy.SafeString,
handlebars = proxy.hbs.handlebars,
templates = proxy.templates,
url = proxy.url;
/**
* @deprecated: will be removed in Ghost 2.0
*/
module.exports = function author(options) {
if (options.fn) {
return 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 = templates.link({
url: url.urlFor('author', {author: this.author}),
text: _.escape(this.author.name)
});
} else {
output = _.escape(this.author.name);
}
}
return new SafeString(output);
};