mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
🐛 Fixed AssetHelper not working with svg (#13978)
loses TryGhost#13971 This fixes an issue with links containing # anchor. It makes sure the # part is at the end of the url like url?v=hash#anhor Co-authored-by: Hannah Wolfe <github.erisds@gmail.com>
This commit is contained in:
parent
af240816d8
commit
f1b71f7fd7
2 changed files with 16 additions and 0 deletions
|
@ -41,9 +41,20 @@ function getAssetUrl(path, hasMinFile) {
|
|||
config.set('assetHash', (crypto.createHash('md5').update(Date.now().toString()).digest('hex')).substring(0, 10));
|
||||
}
|
||||
|
||||
// if url has # make sure the hash is at th right place
|
||||
let anchor;
|
||||
if (path.match('#')) {
|
||||
const index = output.indexOf('#');
|
||||
anchor = output.substring(index);
|
||||
output = output.slice(0, index);
|
||||
}
|
||||
|
||||
// Finally add the asset hash to the output URL
|
||||
output += '?v=' + config.get('assetHash');
|
||||
|
||||
if (anchor) {
|
||||
output += anchor;
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,11 @@ describe('getAssetUrl', function () {
|
|||
testUrl.should.equal('/public/myfile.js?v=' + config.get('assetHash'));
|
||||
});
|
||||
|
||||
it('should return hash before #', function () {
|
||||
const testUrl = getAssetUrl('myfile.svg#arrow-up');
|
||||
testUrl.should.equal(`/assets/myfile.svg?v=${config.get('assetHash')}#arrow-up`);
|
||||
});
|
||||
|
||||
describe('favicon', function () {
|
||||
it('should not add asset to url if favicon.ico', function () {
|
||||
const testUrl = getAssetUrl('favicon.ico');
|
||||
|
|
Loading…
Reference in a new issue