Ghost/core/server/data/meta/asset_url.js

34 lines
753 B
JavaScript
Raw Normal View History

var config = require('../../config');
function getAssetUrl(path, isAdmin, minify) {
var output = '';
output += config.paths.subdir + '/';
if (!path.match(/^favicon\.ico$/) && !path.match(/^shared/) && !path.match(/^asset/)) {
if (isAdmin) {
output += 'ghost/';
} else {
output += 'assets/';
}
}
// Get rid of any leading slash on the path
path = path.replace(/^\//, '');
// replace ".foo" with ".min.foo" in production
if (minify) {
path = path.replace(/\.([^\.]*)$/, '.min.$1');
}
output += path;
if (!path.match(/^favicon\.ico$/)) {
output = output + '?v=' + config.assetHash;
}
return output;
}
module.exports = getAssetUrl;