mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 22:43:30 +03:00
c32cc3e48b
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
38 lines
1.1 KiB
JavaScript
38 lines
1.1 KiB
JavaScript
// # Asset helper
|
|
// Usage: `{{asset "css/screen.css"}}`
|
|
//
|
|
// Returns the path to the specified asset.
|
|
const {metaData, urlUtils} = require('../services/proxy');
|
|
const {SafeString} = require('../services/rendering');
|
|
|
|
const errors = require('@tryghost/errors');
|
|
const tpl = require('@tryghost/tpl');
|
|
const get = require('lodash/get');
|
|
const {getAssetUrl} = metaData;
|
|
|
|
const messages = {
|
|
pathIsRequired: 'The {{asset}} helper must be passed a path'
|
|
};
|
|
|
|
module.exports = function asset(path, options) {
|
|
const hasMinFile = get(options, 'hash.hasMinFile');
|
|
|
|
if (!path) {
|
|
throw new errors.IncorrectUsageError({
|
|
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)
|
|
);
|
|
};
|