Ghost/core/server/data/meta/asset_url.js
Aileen Nowak 83f084608f 💁🏻 Moveshared/ to server/public (#8273)
refs #8221

Instead of serving our shared assets from a `shared/` folder, we move the file, which are used server side to `server/public`.
Adds a new `config.paths` entry: `publicFilePath` and renames the middleware to serve the files to reflect the changes.
Adds `404-ghost.png` images to be used by the server side rendered default template `error.hbs`.
2017-04-07 13:21:41 +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(/^public/) && !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;