Ghost/core/server/data/meta/asset_url.js
Hannah Wolfe 264661ee09 🐛 Refresh assetHash on theme override (#7430)
closes #7423

- Extend our dirty theme override cache clear hack to also reset the asset hash
_ This brings alpha into line with the LTS branch
- This still needs a rewrite for Ghost 1.0.0 🙄
2016-09-23 13:05:44 +02:00

39 lines
913 B
JavaScript

var config = require('../../config'),
utils = require('../../utils');
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', utils.generateAssetHash());
}
output = output + '?v=' + config.get('assetHash');
}
return output;
}
module.exports = getAssetUrl;