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
|
|
|
|
|
|
|
|
var hbs = require('express-hbs'),
|
|
|
|
config = require('../config'),
|
|
|
|
utils = require('./utils'),
|
|
|
|
asset;
|
|
|
|
|
|
|
|
asset = function (context, options) {
|
|
|
|
var output = '',
|
2015-03-08 20:09:57 +03:00
|
|
|
isAdmin,
|
|
|
|
minify;
|
|
|
|
|
|
|
|
if (options && options.hash) {
|
|
|
|
isAdmin = options.hash.ghost;
|
|
|
|
minify = options.hash.minifyInProduction;
|
|
|
|
}
|
2014-10-10 18:54:07 +04:00
|
|
|
|
|
|
|
output += config.paths.subdir + '/';
|
|
|
|
|
|
|
|
if (!context.match(/^favicon\.ico$/) && !context.match(/^shared/) && !context.match(/^asset/)) {
|
|
|
|
if (isAdmin) {
|
|
|
|
output += 'ghost/';
|
|
|
|
} else {
|
|
|
|
output += 'assets/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get rid of any leading slash on the context
|
|
|
|
context = context.replace(/^\//, '');
|
2015-03-08 20:09:57 +03:00
|
|
|
|
|
|
|
// replace ".foo" with ".min.foo" in production
|
|
|
|
if (utils.isProduction && minify) {
|
|
|
|
context = context.replace('.', '.min.');
|
|
|
|
}
|
|
|
|
|
2014-10-10 18:54:07 +04:00
|
|
|
output += context;
|
|
|
|
|
|
|
|
if (!context.match(/^favicon\.ico$/)) {
|
|
|
|
output = utils.assetTemplate({
|
|
|
|
source: output,
|
|
|
|
version: config.assetHash
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return new hbs.handlebars.SafeString(output);
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = asset;
|