2014-10-10 09:54:07 -05:00
|
|
|
// # 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
|
|
|
|
|
2014-12-28 14:38:29 -05:00
|
|
|
var config = require('../config'),
|
2014-10-10 09:54:07 -05:00
|
|
|
schema = require('../data/schema').checks,
|
|
|
|
url;
|
|
|
|
|
|
|
|
url = function (options) {
|
|
|
|
var absolute = options && options.hash.absolute;
|
|
|
|
|
|
|
|
if (schema.isPost(this)) {
|
2014-12-28 14:38:29 -05:00
|
|
|
return config.urlFor('post', {post: this}, absolute);
|
2014-10-10 09:54:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (schema.isTag(this)) {
|
2014-12-28 14:38:29 -05:00
|
|
|
return config.urlFor('tag', {tag: this}, absolute);
|
2014-10-10 09:54:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (schema.isUser(this)) {
|
2014-12-28 14:38:29 -05:00
|
|
|
return config.urlFor('author', {author: this}, absolute);
|
2014-10-10 09:54:07 -05:00
|
|
|
}
|
|
|
|
|
2015-01-28 00:57:19 -05:00
|
|
|
if (schema.isNav(this)) {
|
|
|
|
return config.urlFor('nav', {nav: this}, absolute);
|
|
|
|
}
|
|
|
|
|
2014-12-28 14:38:29 -05:00
|
|
|
return config.urlFor(this, absolute);
|
2014-10-10 09:54:07 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = url;
|