0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00
ghost/core/server/helpers/img_url.js
Hannah Wolfe bcf5a1bc34
Switch to Eslint (#9197)
refs #9178

* Add eslint deps, remove old lint deps
* Add eslint config, remove old lint configs
* Config for server and tests are different
* Tweaked rules to suit us
* Fix linting in codebase - lots of indent changes.
* Fix a real broken test
2017-11-01 13:44:54 +00:00

38 lines
1.2 KiB
JavaScript

// Usage:
// `{{img_url feature_image}}`
// `{{img_url profile_image absolute="true"}}`
// Note:
// `{{img_url}}` - does not work, argument is required
//
// Returns the URL for the current object scope i.e. If inside a post scope will return image permalink
// `absolute` flag outputs absolute URL, else URL is relative.
var proxy = require('./proxy'),
logging = require('../logging'),
i18n = require('../i18n'),
url = proxy.url;
module.exports = function imgUrl(attr, options) {
// CASE: if no attribute is passed, e.g. `{{img_url}}` we show a warning
if (arguments.length < 2) {
logging.warn(i18n.t('warnings.helpers.img_url.attrIsRequired'));
return;
}
var absolute = options && options.hash && options.hash.absolute;
// CASE: if attribute is passed, but it is undefined, then the attribute was
// an unknown value, e.g. {{img_url feature_img}} and we also show a warning
if (attr === undefined) {
logging.warn(i18n.t('warnings.helpers.img_url.attrIsRequired'));
return;
}
if (attr) {
return url.urlFor('image', {image: attr}, absolute);
}
// CASE: if you pass e.g. cover_image, but it is not set, then attr is null!
// in this case we don't show a warning
};