2016-09-12 14:53:04 +03:00
|
|
|
var config = require('../../config'),
|
2016-09-23 14:05:44 +03:00
|
|
|
utils = require('../../utils');
|
2016-01-17 13:07:52 +03:00
|
|
|
|
2016-02-21 21:48:44 +03:00
|
|
|
function getAssetUrl(path, isAdmin, minify) {
|
2016-01-17 13:07:52 +03:00
|
|
|
var output = '';
|
|
|
|
|
2016-09-12 14:53:04 +03:00
|
|
|
output += utils.url.getSubdir() + '/';
|
2016-01-17 13:07:52 +03:00
|
|
|
|
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/';
|
|
|
|
}
|
2016-10-08 01:05:36 +03:00
|
|
|
|
|
|
|
output += 'assets/';
|
2016-01-17 13:07:52 +03:00
|
|
|
}
|
|
|
|
|
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-09-13 21:28:20 +03:00
|
|
|
if (!config.get('assetHash')) {
|
2016-09-23 14:05:44 +03:00
|
|
|
config.set('assetHash', utils.generateAssetHash());
|
2016-09-13 21:28:20 +03:00
|
|
|
}
|
|
|
|
|
2016-09-13 18:41:14 +03:00
|
|
|
output = output + '?v=' + config.get('assetHash');
|
2016-01-17 13:07:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getAssetUrl;
|