mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
1404745b50
refs #10496 - currently {{asset this/is/not/a.string}} would throw a 500 error - this commit changes that to make it throw a sensible 400 + incorrect usage error
24 lines
737 B
JavaScript
24 lines
737 B
JavaScript
// # Asset helper
|
|
// Usage: `{{asset "css/screen.css"}}`, `{{asset "css/screen.css" ghost="true"}}`
|
|
//
|
|
// Returns the path to the specified asset. The ghost flag outputs the asset path for the Ghost admin
|
|
const proxy = require('./proxy'),
|
|
get = require('lodash/get'),
|
|
i18n = proxy.i18n,
|
|
errors = proxy.errors,
|
|
getAssetUrl = proxy.metaData.getAssetUrl,
|
|
SafeString = proxy.SafeString;
|
|
|
|
module.exports = function asset(path, options) {
|
|
const hasMinFile = get(options, 'hash.hasMinFile');
|
|
|
|
if (!path) {
|
|
throw new errors.IncorrectUsageError({
|
|
message: i18n.t('warnings.helpers.asset.pathIsRequired')
|
|
});
|
|
}
|
|
|
|
return new SafeString(
|
|
getAssetUrl(path, hasMinFile)
|
|
);
|
|
};
|