mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 22:02:11 +03:00
6f457768a2
needed for #4852 Before this, calling `{{url}}` with a nav context from #4541 would output `/`. This adds a check in `urlFor` that looks for keys in a nav context object, namely `slug`, `current`, `label`, & `url`. This change allows for a url to pass through if used in a nav context. * adds `schema.isNav()` * adds tests to `url_spec.js` * handles absolute urls correctly even if `absolute=true`
34 lines
889 B
JavaScript
34 lines
889 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 config = require('../config'),
|
|
schema = require('../data/schema').checks,
|
|
url;
|
|
|
|
url = function (options) {
|
|
var absolute = options && options.hash.absolute;
|
|
|
|
if (schema.isPost(this)) {
|
|
return config.urlFor('post', {post: this}, absolute);
|
|
}
|
|
|
|
if (schema.isTag(this)) {
|
|
return config.urlFor('tag', {tag: this}, absolute);
|
|
}
|
|
|
|
if (schema.isUser(this)) {
|
|
return config.urlFor('author', {author: this}, absolute);
|
|
}
|
|
|
|
if (schema.isNav(this)) {
|
|
return config.urlFor('nav', {nav: this}, absolute);
|
|
}
|
|
|
|
return config.urlFor(this, absolute);
|
|
};
|
|
|
|
module.exports = url;
|