inserted directory exists check when rendering md and html, completed index and page html rendering sequence chain

pull/20/head
Ro 5 years ago
parent f6fc242d9c
commit 7243e5ec32

@ -82,7 +82,7 @@ export default class Book {
'/' + '/' +
moment(body.created).format('MM') + moment(body.created).format('MM') +
'/' '/'
); ).then(() => {
if (body.layout !== 'page') layout = body.layout; if (body.layout !== 'page') layout = body.layout;
if (body.layout === null || body.layout === 'null') layout = 'page'; if (body.layout === null || body.layout === 'null') layout = 'page';
var pageWrite = var pageWrite =
@ -171,6 +171,8 @@ export default class Book {
resolve(response); resolve(response);
} }
}); });
});
break; break;
case DataEvent.API_PAGE_DELETE: case DataEvent.API_PAGE_DELETE:
this.getPage(id) this.getPage(id)

@ -7,6 +7,7 @@ const tags_list = require('../../site/tags.json');
const pug = require('pug'); const pug = require('pug');
const md = require('markdown-it')('commonmark'); const md = require('markdown-it')('commonmark');
const _ = require('lodash'); const _ = require('lodash');
const moment = require('moment');
export default class Render { export default class Render {
//-------------------------- //--------------------------
@ -28,7 +29,21 @@ export default class Render {
let response = []; let response = [];
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;
let path =
'public/' +
moment(page.metadata.created).format('YYYY') +
'/' +
moment(page.metadata.created).format('MM') +
'/';
if (page.metadata.layout === 'index') { 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, { let buffed = sanitize(page.content, {
allowedTags: ['del', 'a', 'iframe', 'img'], allowedTags: ['del', 'a', 'iframe', 'img'],
allowedAttributes: { allowedAttributes: {
@ -47,13 +62,14 @@ export default class Render {
buffed = new StringUtils().decodeHTML(buffed); buffed = new StringUtils().decodeHTML(buffed);
let html = md.render(buffed, { html: true, xhtmlOut: true }); let html = md.render(buffed, { html: true, xhtmlOut: true });
let file = pug.renderFile('content/themes/' + theme + '/index.pug', { let file = pug.renderFile(template, {
title: page.metadata.title, title: page.metadata.title,
default_bg: page.metadata.feature, default_bg: page.metadata.feature,
content_index: html content: html
}); });
fs.writeFile('public/index.html', file, err => { fs.ensureDir(path).then(() => {
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) {
@ -68,7 +84,7 @@ export default class Render {
}; };
resolve(response); resolve(response);
}); });
} });
} }
}); });
} }

@ -11,7 +11,7 @@ router.get('/', function (req, res) {
.then(obj => { .then(obj => {
settings = obj; settings = obj;
}) })
.catch(err => { .catch(() => {
//console.error(err); //console.error(err);
}); });
loadThemes().then(themes => { loadThemes().then(themes => {

Loading…
Cancel
Save