mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 19:52:01 +03:00
2c6d43a0c0
no issue - Split theme helpers into individual files for each - Do the same for tests - Have utils to share some things between them - Move assetHash onto config
40 lines
1.1 KiB
JavaScript
40 lines
1.1 KiB
JavaScript
// # Asset helper
|
|
// Usage: `{{asset "css/screen.css"}}`, `{{asset "css/screen.css" ghost="true"}}`
|
|
//
|
|
// Returns the path to the specified asset. The ghost flag outputs the asset path for the Ghost admin
|
|
|
|
var hbs = require('express-hbs'),
|
|
config = require('../config'),
|
|
utils = require('./utils'),
|
|
asset;
|
|
|
|
asset = function (context, options) {
|
|
var output = '',
|
|
isAdmin = options && options.hash && options.hash.ghost;
|
|
|
|
output += config.paths.subdir + '/';
|
|
|
|
if (!context.match(/^favicon\.ico$/) && !context.match(/^shared/) && !context.match(/^asset/)) {
|
|
if (isAdmin) {
|
|
output += 'ghost/';
|
|
} else {
|
|
output += 'assets/';
|
|
}
|
|
}
|
|
|
|
// Get rid of any leading slash on the context
|
|
context = context.replace(/^\//, '');
|
|
output += context;
|
|
|
|
if (!context.match(/^favicon\.ico$/)) {
|
|
output = utils.assetTemplate({
|
|
source: output,
|
|
version: config.assetHash
|
|
});
|
|
}
|
|
|
|
return new hbs.handlebars.SafeString(output);
|
|
};
|
|
|
|
module.exports = asset;
|