You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

  1. require('../core/worker')
  2. const _ = require('lodash')
  3. /* global WIKI */
  4. WIKI.models = require('../core/db').init()
  5. module.exports = async (job) => {
  6. WIKI.logger.info(`Rendering page ${job.data.page.path}...`)
  7. try {
  8. let output = job.data.page.content
  9. for (let core of job.data.pipeline) {
  10. const renderer = require(`../modules/rendering/${_.kebabCase(core.key)}/renderer.js`)
  11. output = await renderer.render.call({
  12. config: core.config,
  13. children: core.children,
  14. page: job.data.page,
  15. input: output
  16. })
  17. }
  18. // Save to DB
  19. await WIKI.models.pages.query()
  20. .patch({ render: output })
  21. .where('id', job.data.page.id)
  22. // Save to cache
  23. await WIKI.models.pages.savePageToCache({
  24. ...job.data.page,
  25. render: output
  26. })
  27. WIKI.logger.info(`Rendering page ${job.data.page.path}: [ COMPLETED ]`)
  28. } catch (err) {
  29. WIKI.logger.error(`Rendering page ${job.data.page.path}: [ FAILED ]`)
  30. WIKI.logger.error(err.message)
  31. }
  32. }