2014-10-10 15:54:07 +01:00
|
|
|
// # Ghost Foot Helper
|
|
|
|
// Usage: `{{ghost_foot}}`
|
|
|
|
//
|
|
|
|
// Outputs scripts and other assets at the bottom of a Ghost theme
|
2021-09-28 15:06:33 +01:00
|
|
|
const {settingsCache} = require('../services/proxy');
|
2022-04-05 17:38:46 +01:00
|
|
|
const {SafeString} = require('../services/handlebars');
|
2020-03-30 21:23:02 +01:00
|
|
|
const _ = require('lodash');
|
2014-10-10 15:54:07 +01:00
|
|
|
|
2017-11-01 13:44:54 +00:00
|
|
|
// We use the name ghost_foot to match the helper for consistency:
|
|
|
|
module.exports = function ghost_foot(options) { // eslint-disable-line camelcase
|
2020-04-29 16:44:27 +01:00
|
|
|
const foot = [];
|
|
|
|
|
2020-07-01 17:44:59 +01:00
|
|
|
const globalCodeinjection = settingsCache.get('codeinjection_foot');
|
2020-04-29 16:44:27 +01:00
|
|
|
const postCodeinjection = options.data.root && options.data.root.post ? options.data.root.post.codeinjection_foot : null;
|
2020-07-10 14:20:22 +02:00
|
|
|
const tagCodeinjection = options.data.root && options.data.root.tag ? options.data.root.tag.codeinjection_foot : null;
|
2017-03-23 19:00:58 +00:00
|
|
|
|
2017-08-02 15:06:51 +04:00
|
|
|
if (!_.isEmpty(globalCodeinjection)) {
|
|
|
|
foot.push(globalCodeinjection);
|
|
|
|
}
|
|
|
|
|
2017-08-02 13:38:19 +04:00
|
|
|
if (!_.isEmpty(postCodeinjection)) {
|
|
|
|
foot.push(postCodeinjection);
|
2017-03-23 19:00:58 +00:00
|
|
|
}
|
2014-10-10 15:54:07 +01:00
|
|
|
|
2020-07-10 14:20:22 +02:00
|
|
|
if (!_.isEmpty(tagCodeinjection)) {
|
|
|
|
foot.push(tagCodeinjection);
|
|
|
|
}
|
|
|
|
|
2019-04-15 16:15:32 +02:00
|
|
|
return new SafeString(foot.join(' ').trim());
|
2014-10-10 15:54:07 +01:00
|
|
|
};
|