2018-08-09 04:07:15 +00:00
|
|
|
require('../core/worker')
|
|
|
|
|
2018-09-10 00:33:10 +00:00
|
|
|
const _ = require('lodash')
|
|
|
|
|
2018-08-09 04:07:15 +00:00
|
|
|
/* global WIKI */
|
|
|
|
|
2018-08-20 05:02:57 +00:00
|
|
|
WIKI.models = require('../core/db').init()
|
|
|
|
|
2018-08-09 04:07:15 +00:00
|
|
|
module.exports = async (job) => {
|
2018-09-10 00:33:10 +00:00
|
|
|
WIKI.logger.info(`Rendering page ${job.data.page.path}...`)
|
2018-08-09 04:07:15 +00:00
|
|
|
|
|
|
|
try {
|
2018-09-10 00:33:10 +00:00
|
|
|
let output = job.data.page.content
|
|
|
|
for (let core of job.data.pipeline) {
|
|
|
|
const renderer = require(`../modules/rendering/${_.kebabCase(core.key)}/renderer.js`)
|
|
|
|
output = await renderer.render.call({
|
|
|
|
config: core.config,
|
|
|
|
children: core.children,
|
|
|
|
page: job.data.page,
|
|
|
|
input: output
|
|
|
|
})
|
|
|
|
}
|
2018-09-16 00:58:23 +00:00
|
|
|
|
|
|
|
// Save to DB
|
|
|
|
await WIKI.models.pages.query()
|
|
|
|
.patch({ render: output })
|
|
|
|
.where('id', job.data.page.id)
|
|
|
|
|
|
|
|
// Save to cache
|
|
|
|
await WIKI.models.pages.savePageToCache({
|
|
|
|
...job.data.page,
|
|
|
|
render: output
|
|
|
|
})
|
2018-09-10 00:33:10 +00:00
|
|
|
|
|
|
|
WIKI.logger.info(`Rendering page ${job.data.page.path}: [ COMPLETED ]`)
|
2018-08-09 04:07:15 +00:00
|
|
|
} catch (err) {
|
2018-09-10 00:33:10 +00:00
|
|
|
WIKI.logger.error(`Rendering page ${job.data.page.path}: [ FAILED ]`)
|
2018-08-09 04:07:15 +00:00
|
|
|
WIKI.logger.error(err.message)
|
|
|
|
}
|
|
|
|
}
|