|
|
@ -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,32 +29,47 @@ 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') {
|
|
|
|
let buffed = sanitize(page.content, {
|
|
|
|
template = 'content/themes/' + theme + '/index.pug';
|
|
|
|
allowedTags: ['del', 'a', 'iframe', 'img'],
|
|
|
|
writeFile = 'public/index.html';
|
|
|
|
allowedAttributes: {
|
|
|
|
} else {
|
|
|
|
a: ['href', 'name', 'target'],
|
|
|
|
writeFile = path + page.metadata.slug + '.html';
|
|
|
|
img: ['src'],
|
|
|
|
template = 'content/themes/' + theme + '/page.pug';
|
|
|
|
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('content/themes/' + theme + '/index.pug', {
|
|
|
|
allowedAttributes: {
|
|
|
|
title: page.metadata.title,
|
|
|
|
a: ['href', 'name', 'target'],
|
|
|
|
default_bg: page.metadata.feature,
|
|
|
|
img: ['src'],
|
|
|
|
content_index: html
|
|
|
|
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
|
|
|
|
// 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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|