deleted paged no longer render, render resolves once instead of multiple times

pull/20/head
Ro 5 years ago
parent c1615602c8
commit a746ddd0aa

@ -2,7 +2,6 @@ import * as DataEvent from '../../src/com/events/DataEvent';
import StringUtils from '../../src/com/utils/StringUtils'; import StringUtils from '../../src/com/utils/StringUtils';
import fs from 'fs-extra'; import fs from 'fs-extra';
import sanitize from 'sanitize-html'; import sanitize from 'sanitize-html';
import Settings from './Settings';
const config = require('../../site/settings.json'); const config = require('../../site/settings.json');
const tags_list = require('../../site/tags.json'); const tags_list = require('../../site/tags.json');
const pug = require('pug'); const pug = require('pug');
@ -28,66 +27,76 @@ export default class Render {
publishAll(pages, theme) { publishAll(pages, theme) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let response = []; let response = [];
let count = _.filter(pages, page => {
return page.metadata.deleted === false;
}).length;
let rendered = 0;
for (let index = 0; index < pages.length; index++) { for (let index = 0; index < pages.length; index++) {
const page = pages[index]; const page = pages[index];
let writeFile, template; if (page.metadata.deleted === false) {
let path = let writeFile, template;
'public/' + let path =
moment(page.metadata.created).format('YYYY') + 'public/' +
'/' + moment(page.metadata.created).format('YYYY') +
moment(page.metadata.created).format('MM') + '/' +
'/'; moment(page.metadata.created).format('MM') +
if (page.metadata.layout === 'index') { '/';
template = 'content/themes/' + theme + '/index.pug'; if (page.metadata.layout === 'index') {
writeFile = 'public/index.html'; template = 'content/themes/' + theme + '/index.pug';
} else { writeFile = 'public/index.html';
writeFile = path + page.metadata.slug + '.html'; } else {
template = 'content/themes/' + theme + '/page.pug'; 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'
]
} }
});
buffed = new StringUtils().decodeHTML(buffed); let buffed = sanitize(page.content, {
let html = md.render(buffed, { html: true, xhtmlOut: true }); allowedTags: ['del', 'a', 'iframe', 'img'],
let file = pug.renderFile(template, { allowedAttributes: {
title: page.metadata.title, a: ['href', 'name', 'target'],
default_bg: page.metadata.feature, img: ['src'],
content: html, iframe: [
tags: page.metadata.tags, 'height',
menu: config.menu 'width',
}); 'src',
'frameborder',
'allow',
'allowfullscreen'
]
}
});
fs.ensureDir(path).then(() => { buffed = new StringUtils().decodeHTML(buffed);
fs.writeFile(writeFile, file, err => { let html = md.render(buffed, { html: true, xhtmlOut: true });
// throws an error, you could also catch it here let file = pug.renderFile(template, {
title: page.metadata.title,
default_bg: page.metadata.feature,
content: html,
tags: page.metadata.tags,
menu: config.menu
});
if (err) { fs.ensureDir(path).then(() => {
response = { type: DataEvent.PAGES_NOT_RENDERED, message: err }; fs.writeFile(writeFile, file, err => {
reject(response); // 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 // success case, the file was saved
});
});
rendered = ++rendered;
if (rendered === count) {
response = { response = {
type: DataEvent.PAGES_RENDERED, type: DataEvent.PAGES_RENDERED,
message: 'All Pages Rendered. Sweet.' message: 'All Pages Rendered. Sweet.'
}; };
resolve(response); resolve(response);
}); }
}); } else {
//don't render delete pages
}
} }
}); });
} }

Loading…
Cancel
Save