Ghost/core/server/helpers/url.js
Hannah Wolfe 2c6d43a0c0 Refactor helpers & tests into individual files
no issue

- Split theme helpers into individual files for each
- Do the same for tests
- Have utils to share some things between them
- Move assetHash onto config
2014-10-14 22:52:40 +02:00

32 lines
929 B
JavaScript

// # URL helper
// Usage: `{{url}}`, `{{url absolute="true"}}`
//
// Returns the URL for the current object scope i.e. If inside a post scope will return post permalink
// `absolute` flag outputs absolute URL, else URL is relative
var Promise = require('bluebird'),
config = require('../config'),
api = require('../api'),
schema = require('../data/schema').checks,
url;
url = function (options) {
var absolute = options && options.hash.absolute;
if (schema.isPost(this)) {
return config.urlForPost(api.settings, this, absolute);
}
if (schema.isTag(this)) {
return Promise.resolve(config.urlFor('tag', {tag: this}, absolute));
}
if (schema.isUser(this)) {
return Promise.resolve(config.urlFor('author', {author: this}, absolute));
}
return Promise.resolve(config.urlFor(this, absolute));
};
module.exports = url;