2016-09-12 13:53:04 +02:00
|
|
|
var config = require('../../config'),
|
2016-09-13 20:28:20 +02:00
|
|
|
utils = require('../../utils'),
|
|
|
|
crypto = require('crypto');
|
2016-01-17 02:07:52 -08:00
|
|
|
|
2016-02-21 18:48:44 +00:00
|
|
|
function getAssetUrl(path, isAdmin, minify) {
|
2016-01-17 02:07:52 -08:00
|
|
|
var output = '';
|
|
|
|
|
2016-09-12 13:53:04 +02:00
|
|
|
output += utils.url.getSubdir() + '/';
|
2016-01-17 02:07:52 -08:00
|
|
|
|
2016-02-21 18:48:44 +00:00
|
|
|
if (!path.match(/^favicon\.ico$/) && !path.match(/^shared/) && !path.match(/^asset/)) {
|
2016-01-17 02:07:52 -08:00
|
|
|
if (isAdmin) {
|
|
|
|
output += 'ghost/';
|
|
|
|
} else {
|
|
|
|
output += 'assets/';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 18:48:44 +00:00
|
|
|
// Get rid of any leading slash on the path
|
|
|
|
path = path.replace(/^\//, '');
|
2016-01-17 02:07:52 -08:00
|
|
|
|
|
|
|
// replace ".foo" with ".min.foo" in production
|
|
|
|
if (minify) {
|
2016-02-21 18:48:44 +00:00
|
|
|
path = path.replace(/\.([^\.]*)$/, '.min.$1');
|
2016-01-17 02:07:52 -08:00
|
|
|
}
|
|
|
|
|
2016-02-21 18:48:44 +00:00
|
|
|
output += path;
|
2016-01-17 02:07:52 -08:00
|
|
|
|
2016-02-21 18:48:44 +00:00
|
|
|
if (!path.match(/^favicon\.ico$/)) {
|
2016-09-13 20:28:20 +02:00
|
|
|
if (!config.get('assetHash')) {
|
|
|
|
config.set('assetHash', (crypto.createHash('md5').update(config.get('ghostVersion') + Date.now()).digest('hex')).substring(0, 10));
|
|
|
|
}
|
|
|
|
|
2016-09-13 17:41:14 +02:00
|
|
|
output = output + '?v=' + config.get('assetHash');
|
2016-01-17 02:07:52 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = getAssetUrl;
|