Ghost/core/server/data/meta/asset_url.js
Aileen Nowak e06547ae78 Split css server templates (#8234)
closes #8126

* Remove default template dependency on client side CSS

See Issue #8126

Adds these files under /shared
- normalizer.css
- error.css
- extracted.css (for subscribers.css and private.css)

Also makes these files available as public static content

* Remove default template dependency on client CSS

closes #8126
needs e3acd3c

This is a replacement PR of #8217 (thanks @TienSFU25 for the whole work 🤗), because these changes are needed urgently and blocking other work.

Adds a new `ghost.css` file in `/core/shared/` to be used for server side template rendering (`error.hbs`, `subscribe.hbs` and `private.hbs`).
2017-04-04 10:06:38 +01:00

53 lines
1.7 KiB
JavaScript

var config = require('../../config'),
settingsCache = require('../../settings/cache'),
utils = require('../../utils');
function getAssetUrl(path, isAdmin, minify) {
var output = '';
output += utils.url.urlJoin(utils.url.getSubdir(), '/');
if (!path.match(/^favicon\.(ico|png)$/) && !path.match(/^shared/) && !path.match(/^asset/)) {
if (isAdmin) {
output = utils.url.urlJoin(output, 'ghost/');
}
output = utils.url.urlJoin(output, 'assets/');
}
// Serve either uploaded favicon or default
// for favicon, we don't care anymore about the `/` leading slash, as we don't support theme favicons
if (path.match(/\/?favicon\.(ico|png)$/)) {
if (isAdmin) {
output = utils.url.urlJoin(utils.url.getSubdir(), '/favicon.ico');
} else {
if (settingsCache.get('icon')) {
output = utils.url.urlJoin(utils.url.getSubdir(), utils.url.urlFor('image', {image: settingsCache.get('icon')}));
} else {
output = utils.url.urlJoin(utils.url.getSubdir(), '/favicon.ico');
}
}
}
// 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');
}
if (!path.match(/^favicon\.(ico|png)$/)) {
// we don't want to concat the path with our favicon url
output += path;
if (!config.get('assetHash')) {
config.set('assetHash', utils.generateAssetHash());
}
output = output + '?v=' + config.get('assetHash');
}
return output;
}
module.exports = getAssetUrl;