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.
wiki/server/jobs/render-page.js

41 lines
1.0 KiB

require('../core/worker')
const _ = require('lodash')
/* global WIKI */
WIKI.models = require('../core/db').init()
module.exports = async (job) => {
WIKI.logger.info(`Rendering page ${job.data.page.path}...`)
try {
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
})
WIKI.logger.info(`Rendering page ${job.data.page.path}: [ COMPLETED ]`)
} catch (err) {
WIKI.logger.error(`Rendering page ${job.data.page.path}: [ FAILED ]`)
WIKI.logger.error(err.message)
}
}