|
|
|
@ -7,6 +7,7 @@ const tags_list = require('../../site/tags.json');
|
|
|
|
|
const pug = require('pug');
|
|
|
|
|
const md = require('markdown-it')('commonmark');
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
|
|
|
|
|
export default class Render {
|
|
|
|
|
//--------------------------
|
|
|
|
@ -28,32 +29,47 @@ export default class Render {
|
|
|
|
|
let response = [];
|
|
|
|
|
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') {
|
|
|
|
|
let buffed = sanitize(page.content, {
|
|
|
|
|
allowedTags: ['del', 'a', 'iframe', 'img'],
|
|
|
|
|
allowedAttributes: {
|
|
|
|
|
a: ['href', 'name', 'target'],
|
|
|
|
|
img: ['src'],
|
|
|
|
|
iframe: [
|
|
|
|
|
'height',
|
|
|
|
|
'width',
|
|
|
|
|
'src',
|
|
|
|
|
'frameborder',
|
|
|
|
|
'allow',
|
|
|
|
|
'allowfullscreen'
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
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('content/themes/' + theme + '/index.pug', {
|
|
|
|
|
title: page.metadata.title,
|
|
|
|
|
default_bg: page.metadata.feature,
|
|
|
|
|
content_index: html
|
|
|
|
|
});
|
|
|
|
|
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 html = md.render(buffed, { html: true, xhtmlOut: true });
|
|
|
|
|
let file = pug.renderFile(template, {
|
|
|
|
|
title: page.metadata.title,
|
|
|
|
|
default_bg: page.metadata.feature,
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
@ -68,7 +84,7 @@ export default class Render {
|
|
|
|
|
};
|
|
|
|
|
resolve(response);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|