Ghost/core/frontend/helpers/index.js
Hannah Wolfe fc664ac697 Improved helper index, use glob to read directory
- Having to remember to add files to an index.js is a PITA
- We already have glob as a dependency, so use that
- This requires that the file prev_next be renamed to prev_post, which is what it's called as by default
- next_post is an alias of next_post - so this reflects that more closely
2020-04-10 13:08:41 +01:00

16 lines
476 B
JavaScript

const glob = require('glob');
const path = require('path');
const helpers = {};
// We use glob here because it's already a dependency
// If we want to get rid of glob we could use E.g. requiredir
// Or require('fs').readdirSync(__dirname + '/')
let helperFiles = glob.sync('!(index).js', {cwd: __dirname});
helperFiles.forEach((helper) => {
let name = helper.replace(/.js$/, '');
helpers[name] = require(path.join(__dirname, helper));
});
module.exports = helpers;