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