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