Ghost/core/server/helpers/img_url.js
Katharina Irrgang 76bd4fdef6 🙀 Image field naming & new img_url helper (#8364)
* 🙀  change database schema for images
    - rename user/post/tag images
    - contains all the required changes from the schema change

* Refactor helper/meta data
    - rename cover to cover_image
    - also rename default settings to match the pattern
    - rename image to profile_image for user
    - rename image to feature_image for tags/posts

* {{image}} >>> {{img_url}}
    - rename
    - change the functionality
    - attr is required
    - e.g. {{img_url feature_image}}

* gscan 1.0.0
    - update yarn.lock

* Update casper reference: 1.0-changes
    - see 5487b4da8d
2017-04-24 18:21:47 +01:00

40 lines
1.1 KiB
JavaScript

// Usage:
// `{{img_url}}` - does not work, argument is required
// `{{img_url feature_image}}`
// `{{img_url profile_image absolute="true"}}`
//
// 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'),
errors = require('../errors'),
i18n = require('../i18n'),
url = proxy.url;
module.exports = function imgUrl(attr, options) {
var absolute;
// CASE: if you pass e.g. cover_image, but it is not set, then attr is null!
// in this case we don't throw an error
if (!options) {
attr = undefined;
options = attr;
}
absolute = options && options.hash && options.hash.absolute;
if (attr === undefined) {
throw new errors.IncorrectUsageError({
message: i18n.t('warnings.helpers.img_url.attrIsRequired')
});
}
// CASE: property is not set in the model e.g. cover_image
if (attr === null) {
return;
}
return url.urlFor('image', {image: attr}, absolute);
};