From a746ddd0aa3ee84c4fcd7a1adc30132c38518b3a Mon Sep 17 00:00:00 2001 From: Ro Date: Sun, 14 Jun 2020 14:46:45 -0700 Subject: [PATCH] deleted paged no longer render, render resolves once instead of multiple times --- brain/data/Render.js | 109 +++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 50 deletions(-) diff --git a/brain/data/Render.js b/brain/data/Render.js index 108cddd..549ad25 100644 --- a/brain/data/Render.js +++ b/brain/data/Render.js @@ -2,7 +2,6 @@ import * as DataEvent from '../../src/com/events/DataEvent'; import StringUtils from '../../src/com/utils/StringUtils'; import fs from 'fs-extra'; import sanitize from 'sanitize-html'; -import Settings from './Settings'; const config = require('../../site/settings.json'); const tags_list = require('../../site/tags.json'); const pug = require('pug'); @@ -28,66 +27,76 @@ export default class Render { publishAll(pages, theme) { return new Promise((resolve, reject) => { let response = []; + let count = _.filter(pages, page => { + return page.metadata.deleted === false; + }).length; + let rendered = 0; for (let index = 0; index < pages.length; index++) { const page = pages[index]; - let writeFile, template; - let path = - 'public/' + - moment(page.metadata.created).format('YYYY') + - '/' + - moment(page.metadata.created).format('MM') + - '/'; - if (page.metadata.layout === 'index') { - template = 'content/themes/' + theme + '/index.pug'; - writeFile = 'public/index.html'; - } else { - writeFile = path + page.metadata.slug + '.html'; - template = 'content/themes/' + theme + '/page.pug'; - } - - let buffed = sanitize(page.content, { - allowedTags: ['del', 'a', 'iframe', 'img'], - allowedAttributes: { - a: ['href', 'name', 'target'], - img: ['src'], - iframe: [ - 'height', - 'width', - 'src', - 'frameborder', - 'allow', - 'allowfullscreen' - ] + if (page.metadata.deleted === false) { + let writeFile, template; + let path = + 'public/' + + moment(page.metadata.created).format('YYYY') + + '/' + + moment(page.metadata.created).format('MM') + + '/'; + if (page.metadata.layout === 'index') { + template = 'content/themes/' + theme + '/index.pug'; + writeFile = 'public/index.html'; + } else { + writeFile = path + page.metadata.slug + '.html'; + template = 'content/themes/' + theme + '/page.pug'; } - }); - 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, - menu: config.menu - }); - - fs.ensureDir(path).then(() => { - fs.writeFile(writeFile, file, err => { - // throws an error, you could also catch it here - - if (err) { - response = { type: DataEvent.PAGES_NOT_RENDERED, message: err }; - reject(response); + let buffed = sanitize(page.content, { + allowedTags: ['del', 'a', 'iframe', 'img'], + allowedAttributes: { + a: ['href', 'name', 'target'], + img: ['src'], + iframe: [ + 'height', + 'width', + 'src', + 'frameborder', + 'allow', + 'allowfullscreen' + ] } + }); - // success case, the file was saved + 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, + menu: config.menu + }); + + fs.ensureDir(path).then(() => { + fs.writeFile(writeFile, file, err => { + // throws an error, you could also catch it here + if (err) { + response = { type: DataEvent.PAGES_NOT_RENDERED, message: err }; + reject(response); + } + + // success case, the file was saved + }); + }); + rendered = ++rendered; + if (rendered === count) { response = { type: DataEvent.PAGES_RENDERED, message: 'All Pages Rendered. Sweet.' }; resolve(response); - }); - }); + } + } else { + //don't render delete pages + } } }); }