mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-25 11:55:03 +03:00
🐛 Fixed broken assets for theme/design preview
refs https://github.com/TryGhost/Team/issues/1190 - The assets were broken in Admin when the frontend and admin urls were different - Fixed the issue by changing the `asset` helper to output absolute URLs when the frontend/admin urls are differents
This commit is contained in:
parent
6c487ca2c9
commit
c32cc3e48b
@ -2,7 +2,7 @@
|
||||
// Usage: `{{asset "css/screen.css"}}`
|
||||
//
|
||||
// Returns the path to the specified asset.
|
||||
const {metaData} = require('../services/proxy');
|
||||
const {metaData, urlUtils} = require('../services/proxy');
|
||||
const {SafeString} = require('../services/rendering');
|
||||
|
||||
const errors = require('@tryghost/errors');
|
||||
@ -22,6 +22,14 @@ module.exports = function asset(path, options) {
|
||||
message: tpl(messages.pathIsRequired)
|
||||
});
|
||||
}
|
||||
if (typeof urlUtils.getSiteUrl() !== 'undefined'
|
||||
&& typeof urlUtils.getAdminUrl() !== 'undefined'
|
||||
&& urlUtils.getSiteUrl() !== urlUtils.getAdminUrl()) {
|
||||
const target = new URL(getAssetUrl(path, hasMinFile), urlUtils.getSiteUrl());
|
||||
return new SafeString(
|
||||
target.href
|
||||
);
|
||||
}
|
||||
|
||||
return new SafeString(
|
||||
getAssetUrl(path, hasMinFile)
|
||||
|
@ -75,4 +75,27 @@ describe('{{asset}} helper', function () {
|
||||
String(rendered).should.equal('/assets/js/asset.min.js?v=abc');
|
||||
});
|
||||
});
|
||||
|
||||
describe('different admin and site urls', function () {
|
||||
before(function () {
|
||||
configUtils.set({url: 'http://127.0.0.1'});
|
||||
configUtils.set({'admin:url': 'http://localhost'});
|
||||
});
|
||||
|
||||
after(function () {
|
||||
configUtils.restore();
|
||||
});
|
||||
|
||||
it('handles favicon correctly', function () {
|
||||
rendered = asset('favicon.ico');
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('http://127.0.0.1/favicon.ico');
|
||||
});
|
||||
|
||||
it('handles ghost.css for default templates correctly', function () {
|
||||
rendered = asset('public/ghost.css');
|
||||
should.exist(rendered);
|
||||
String(rendered).should.equal('http://127.0.0.1/public/ghost.css?v=abc');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user