mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
f4bee50e86
refs #6982 - was before generated in ConfigManager [ci skip]
39 lines
1 KiB
JavaScript
39 lines
1 KiB
JavaScript
var config = require('../../config'),
|
|
utils = require('../../utils'),
|
|
crypto = require('crypto');
|
|
|
|
function getAssetUrl(path, isAdmin, minify) {
|
|
var output = '';
|
|
|
|
output += utils.url.getSubdir() + '/';
|
|
|
|
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$/)) {
|
|
if (!config.get('assetHash')) {
|
|
config.set('assetHash', (crypto.createHash('md5').update(config.get('ghostVersion') + Date.now()).digest('hex')).substring(0, 10));
|
|
}
|
|
|
|
output = output + '?v=' + config.get('assetHash');
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
module.exports = getAssetUrl;
|