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

This commit is contained in:
Ro 2020-06-14 14:46:45 -07:00
parent c1615602c8
commit a746ddd0aa

View file

@ -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,8 +27,13 @@ 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];
if (page.metadata.deleted === false) {
let writeFile, template; let writeFile, template;
let path = let path =
'public/' + 'public/' +
@ -74,20 +78,25 @@ export default class Render {
fs.ensureDir(path).then(() => { fs.ensureDir(path).then(() => {
fs.writeFile(writeFile, file, err => { fs.writeFile(writeFile, file, err => {
// throws an error, you could also catch it here // throws an error, you could also catch it here
if (err) { if (err) {
response = { type: DataEvent.PAGES_NOT_RENDERED, message: err }; response = { type: DataEvent.PAGES_NOT_RENDERED, message: err };
reject(response); 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
}
} }
}); });
} }