mirror of
https://github.com/strapi/strapi.git
synced 2025-07-13 12:02:10 +00:00
74 lines
1.7 KiB
JavaScript
Executable File
74 lines
1.7 KiB
JavaScript
Executable File
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
|
|
// Node.js core.
|
|
const path = require('path');
|
|
|
|
// Public node modules.
|
|
const _ = require('lodash');
|
|
const consolidate = require('consolidate');
|
|
const views = require('koa-views');
|
|
|
|
/**
|
|
* Public assets hook
|
|
*/
|
|
|
|
module.exports = strapi => {
|
|
return {
|
|
/**
|
|
* Initialize the hook
|
|
*/
|
|
|
|
initialize: function(cb) {
|
|
if (
|
|
_.isPlainObject(strapi.config.middleware.settings.views) &&
|
|
!_.isEmpty(strapi.config.middleware.settings.views)
|
|
) {
|
|
const opts = _.clone(strapi.config.middleware.settings.views);
|
|
|
|
if (opts.hasOwnProperty('default')) {
|
|
opts.extension = opts.default;
|
|
delete opts.default;
|
|
}
|
|
|
|
// Map every template engine in config.
|
|
_.forEach(opts.map, engine => {
|
|
if (!consolidate.requires[engine]) {
|
|
// Try to require them using `consolidate` or throw an error.
|
|
try {
|
|
consolidate.requires[engine] = require(path.resolve(
|
|
strapi.config.appPath,
|
|
'node_modules',
|
|
engine
|
|
));
|
|
} catch (err) {
|
|
strapi.log.error(
|
|
'`' + engine + '` template engine not installed.'
|
|
);
|
|
strapi.log.error(
|
|
'Execute `$ npm install ' + engine + ' --save` to install it.'
|
|
);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Initialize the engine with `consolidate`.
|
|
consolidate[engine];
|
|
});
|
|
|
|
strapi.app.use(
|
|
views(
|
|
path.resolve(strapi.config.appPath, strapi.config.paths.views),
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
|
|
cb();
|
|
}
|
|
};
|
|
};
|