cleaned up package scripts, added tag sorting to settings
parent
4ff6f22e25
commit
fad2c4bc8d
@ -0,0 +1,81 @@
|
||||
import * as DataEvent from '../../src/com/events/DataEvent';
|
||||
import sanitize from 'sanitize-html';
|
||||
import StringUtils from '../../src/com/utils/StringUtils';
|
||||
import fs from 'fs-extra';
|
||||
const pug = require('pug');
|
||||
const md = require('markdown-it')('commonmark');
|
||||
|
||||
export default class Render {
|
||||
//--------------------------
|
||||
// constructor
|
||||
//--------------------------
|
||||
constructor() {}
|
||||
//--------------------------
|
||||
// methods
|
||||
//--------------------------
|
||||
start() {}
|
||||
|
||||
/**
|
||||
* Renders all pages from markdown to html
|
||||
* @parameter theme: current theme being used as defined in settings
|
||||
*/
|
||||
publishAll(theme) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.getPage()
|
||||
.then(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,
|
||||
default_bg: page.metadata.feature,
|
||||
content_index: 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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
// event handlers
|
||||
//--------------------------
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
import * as DataEvent from '../../src/com/events/DataEvent';
|
||||
import fs from 'fs-extra';
|
||||
const settings = require('../../site/settings.json');
|
||||
const _ = require('lodash');
|
||||
|
||||
export default class Settings {
|
||||
//--------------------------
|
||||
// constructor
|
||||
//--------------------------
|
||||
constructor() {}
|
||||
//--------------------------
|
||||
// methods
|
||||
//--------------------------
|
||||
start() {}
|
||||
saveTags(tags) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!_.isEqual(settings.tags, tags)) {
|
||||
settings.tags = tags;
|
||||
fs.writeJson('site/settings.json', settings)
|
||||
.then(() => {
|
||||
let response = {
|
||||
type: DataEvent.SETTINGS_UPDATED,
|
||||
message: 'Settings Saved'
|
||||
};
|
||||
resolve(response);
|
||||
})
|
||||
.catch(err => {
|
||||
reject(err);
|
||||
});
|
||||
} else {
|
||||
let response = {
|
||||
type: DataEvent.SETTINGS_NOT_UPDATED,
|
||||
message: 'Settings Already Saved'
|
||||
};
|
||||
resolve(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//--------------------------
|
||||
// event handlers
|
||||
//--------------------------
|
||||
}
|
Loading…
Reference in New Issue