From a92f624b75b789c14586404fae7ee9932f67d8cf Mon Sep 17 00:00:00 2001 From: Ro Date: Thu, 25 Jun 2020 20:49:12 -0700 Subject: [PATCH] added meta data to html rendering --- brain/api/v1/settings.js | 6 +++++- brain/data/Render.js | 25 +++++++++++++++++++++---- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/brain/api/v1/settings.js b/brain/api/v1/settings.js index cfd436f..2853c6e 100644 --- a/brain/api/v1/settings.js +++ b/brain/api/v1/settings.js @@ -94,7 +94,11 @@ router.post('/publish-pages', (req, res) => { getBookData() .then(result => { render - .publishAll(result.pages, result.settings.global.theme) + .publishAll( + result.pages, + result.settings.global.theme, + req.session.user.handle + ) .then(response => { res.json({ type: response.type, diff --git a/brain/data/Render.js b/brain/data/Render.js index d7f441a..d9b9d13 100644 --- a/brain/data/Render.js +++ b/brain/data/Render.js @@ -24,7 +24,7 @@ export default class Render { * @parameter pages: payload for site pages * @parameter theme: current theme being used as defined in settings */ - publishAll(pages, theme) { + publishAll(pages, theme, author) { return new Promise((resolve, reject) => { settings .load(SETTINGS_FILE) @@ -68,15 +68,28 @@ export default class Render { ] } }); - + let bag = page.metadata.tags.split(','); + let tags = []; + for (let index = 0; index < bag.length; index++) { + let tag = bag[index].trim(); + tags.push({ + label: bag[index], + slug: new StringUtils().cleanString(tag) + }); + } buffed = new StringUtils().decodeHTML(buffed); let html = md.render(buffed, { html: true, xhtmlOut: true }); let file = pug.renderFile(template, { title: page.metadata.title, default_bg: page.metadata.feature, content: html, - tags: page.metadata.tags, + tags: tags, menu: config.menu, + meta: { + who: author, + when: moment(page.metadata.created).fromNow(), + tags: tags + }, welcome_message: page.metadata.title }); @@ -119,7 +132,11 @@ export default class Render { '/' + page.metadata.slug + '.html' - ); + ) + .then() + .catch(err => { + console.log('ERROR', err); + }); } } }