|
|
|
@ -1,11 +1,15 @@
|
|
|
|
|
import fh from 'filehound';
|
|
|
|
|
import fs from 'fs-extra';
|
|
|
|
|
import sanitize from 'sanitize-html';
|
|
|
|
|
import metadataParser from 'markdown-yaml-metadata-parser';
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import * as DataEvent from '../../src/com/events/DataEvent';
|
|
|
|
|
import Navigation from './Navigation';
|
|
|
|
|
import StringUtils from '../../src/com/utils/StringUtils';
|
|
|
|
|
const nav = new Navigation();
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
const pug = require('pug');
|
|
|
|
|
const md = require('markdown-it')('commonmark');
|
|
|
|
|
|
|
|
|
|
export default class Pages {
|
|
|
|
|
//--------------------------
|
|
|
|
@ -173,13 +177,54 @@ export default class Pages {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
publish() {
|
|
|
|
|
publish(theme) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
//let self = this;
|
|
|
|
|
//get pages for rendering
|
|
|
|
|
this.getPage()
|
|
|
|
|
.then(pages => {
|
|
|
|
|
resolve(pages);
|
|
|
|
|
let response = [];
|
|
|
|
|
for (let index = 0; index < pages.length; index++) {
|
|
|
|
|
const page = pages[index];
|
|
|
|
|
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'
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
content: html
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
fs.writeFile('public/index.html', file, err => {
|
|
|
|
|
// 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
|
|
|
|
|
response = {
|
|
|
|
|
type: DataEvent.PAGES_RENDERED,
|
|
|
|
|
message: 'All Pages Rendered. Sweet.'
|
|
|
|
|
};
|
|
|
|
|
resolve(response);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|