wikijs-fork/server/jobs/render-page.js

41 lines
1.0 KiB
JavaScript
Raw Normal View History

require('../core/worker')
2018-09-10 00:33:10 +00:00
const _ = require('lodash')
/* global WIKI */
2018-08-20 05:02:57 +00:00
WIKI.models = require('../core/db').init()
module.exports = async (job) => {
2018-09-10 00:33:10 +00:00
WIKI.logger.info(`Rendering page ${job.data.page.path}...`)
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
})
}
// 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 ]`)
} catch (err) {
2018-09-10 00:33:10 +00:00
WIKI.logger.error(`Rendering page ${job.data.page.path}: [ FAILED ]`)
WIKI.logger.error(err.message)
}
}