compileTemplates.js 538 B

1234567891011121314151617181920
  1. const Handlebars = require("handlebars");
  2. const handlebarsCompiler = Handlebars.compile;
  3. function compileTemplates(config, item) {
  4. return new Promise(function(resolve) {
  5. resolve({
  6. ...item,
  7. template: handlebarsCompiler(item.content)
  8. });
  9. });
  10. }
  11. compileTemplates.withConfig = function(config) {
  12. if (config.partials) {
  13. config.partials.map(partial =>
  14. Handlebars.registerPartial(partial.name, partial.content)
  15. );
  16. }
  17. return item => compileTemplates(config, item);
  18. };
  19. module.exports = compileTemplates;