2014-10-10 18:54:07 +04:00
|
|
|
// # 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
|
|
|
|
|
2016-10-11 15:53:52 +03:00
|
|
|
var config = require('../config'),
|
|
|
|
getAssetUrl = require('../data/meta/asset_url'),
|
2016-01-17 13:07:52 +03:00
|
|
|
hbs = require('express-hbs');
|
2014-10-10 18:54:07 +04:00
|
|
|
|
2016-02-21 21:48:44 +03:00
|
|
|
function asset(path, options) {
|
2016-01-17 13:07:52 +03:00
|
|
|
var isAdmin,
|
2015-03-08 20:09:57 +03:00
|
|
|
minify;
|
|
|
|
|
|
|
|
if (options && options.hash) {
|
|
|
|
isAdmin = options.hash.ghost;
|
|
|
|
minify = options.hash.minifyInProduction;
|
|
|
|
}
|
2016-10-11 15:53:52 +03:00
|
|
|
if (config.get('env') !== 'production') {
|
2016-01-17 13:07:52 +03:00
|
|
|
minify = false;
|
2015-03-08 20:09:57 +03:00
|
|
|
}
|
2016-01-17 13:07:52 +03:00
|
|
|
return new hbs.handlebars.SafeString(
|
2016-02-21 21:48:44 +03:00
|
|
|
getAssetUrl(path, isAdmin, minify)
|
2016-01-17 13:07:52 +03:00
|
|
|
);
|
|
|
|
}
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
module.exports = asset;
|