|
|
|
@ -1,13 +1,13 @@
|
|
|
|
|
import * as DataEvent from '../../src/com/events/DataEvent';
|
|
|
|
|
import StringUtils from '../../src/com/utils/StringUtils';
|
|
|
|
|
import Settings, { SETTINGS_FILE, SETTINGS_TAG } from './Settings';
|
|
|
|
|
import fs from 'fs-extra';
|
|
|
|
|
import sanitize from 'sanitize-html';
|
|
|
|
|
const config = require('../../site/settings.json');
|
|
|
|
|
const tags_list = require('../../site/tags.json');
|
|
|
|
|
const pug = require('pug');
|
|
|
|
|
const md = require('markdown-it')('commonmark');
|
|
|
|
|
const _ = require('lodash');
|
|
|
|
|
const moment = require('moment');
|
|
|
|
|
const settings = new Settings();
|
|
|
|
|
|
|
|
|
|
export default class Render {
|
|
|
|
|
//--------------------------
|
|
|
|
@ -26,6 +26,9 @@ export default class Render {
|
|
|
|
|
*/
|
|
|
|
|
publishAll(pages, theme) {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
settings
|
|
|
|
|
.load(SETTINGS_FILE)
|
|
|
|
|
.then(config => {
|
|
|
|
|
let response = [];
|
|
|
|
|
let count = _.filter(pages, page => {
|
|
|
|
|
return page.metadata.deleted === false;
|
|
|
|
@ -79,7 +82,10 @@ export default class Render {
|
|
|
|
|
fs.writeFile(writeFile, file, err => {
|
|
|
|
|
// throws an error, you could also catch it here
|
|
|
|
|
if (err) {
|
|
|
|
|
response = { type: DataEvent.PAGES_NOT_RENDERED, message: err };
|
|
|
|
|
response = {
|
|
|
|
|
type: DataEvent.PAGES_NOT_RENDERED,
|
|
|
|
|
message: err
|
|
|
|
|
};
|
|
|
|
|
reject(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -98,11 +104,18 @@ export default class Render {
|
|
|
|
|
//don't render delete pages
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
publishTags(pages) {
|
|
|
|
|
let self = this;
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let tags = tags_list.tags;
|
|
|
|
|
self.loadRenderData()
|
|
|
|
|
.then(result => {
|
|
|
|
|
let tags = result.tags.tags;
|
|
|
|
|
let renderList = [];
|
|
|
|
|
for (let index = 0; index < tags.length; index++) {
|
|
|
|
|
let tag = tags[index];
|
|
|
|
@ -112,7 +125,10 @@ export default class Render {
|
|
|
|
|
let page = pages[i];
|
|
|
|
|
|
|
|
|
|
if (_.includes(page.metadata.tags, tag.tag_name)) {
|
|
|
|
|
pageList.push({ title: page.metadata.title, slug: page.metadata.slug });
|
|
|
|
|
pageList.push({
|
|
|
|
|
title: page.metadata.title,
|
|
|
|
|
slug: page.metadata.slug
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
renderList.push({ tag: tag.tag_name, tag_list: pageList, slug: tag.slug });
|
|
|
|
@ -120,12 +136,15 @@ export default class Render {
|
|
|
|
|
let response = [];
|
|
|
|
|
for (let index = 0; index < renderList.length; index++) {
|
|
|
|
|
let item = renderList[index];
|
|
|
|
|
let file = pug.renderFile('content/themes/' + config.global.theme + '/tags.pug', {
|
|
|
|
|
let file = pug.renderFile(
|
|
|
|
|
'content/themes/' + result.settings.global.theme + '/tags.pug',
|
|
|
|
|
{
|
|
|
|
|
title: item.tag,
|
|
|
|
|
default_bg: config.global.background,
|
|
|
|
|
default_bg: result.settings.global.background,
|
|
|
|
|
content_tags: 'THESE ARE TAGS',
|
|
|
|
|
tag_list: item.tag_list
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fs.writeFile('public/tags/' + item.slug + '.html', file, err => {
|
|
|
|
|
// throws an error, you could also catch it here
|
|
|
|
@ -141,15 +160,25 @@ export default class Render {
|
|
|
|
|
resolve(response);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
publishArchive(archive) {
|
|
|
|
|
let file = pug.renderFile('content/themes/' + config.global.theme + '/archive.pug', {
|
|
|
|
|
settings
|
|
|
|
|
.load(SETTINGS_FILE)
|
|
|
|
|
.then(settings => {
|
|
|
|
|
let file = pug.renderFile(
|
|
|
|
|
'content/themes/' + settings.global.theme + '/archive.pug',
|
|
|
|
|
{
|
|
|
|
|
title: 'ARCHIVES',
|
|
|
|
|
default_bg: config.global.background,
|
|
|
|
|
default_bg: settings.global.background,
|
|
|
|
|
content_tags: 'COLD STORAGE',
|
|
|
|
|
archives: archive
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fs.writeFile('public/archives.html', file, err => {
|
|
|
|
|
// throws an error, you could also catch it here
|
|
|
|
@ -159,6 +188,25 @@ export default class Render {
|
|
|
|
|
}
|
|
|
|
|
// success case, the file was saved
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
console.log(err);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
loadRenderData() {
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let getSettings = settings.load(SETTINGS_FILE);
|
|
|
|
|
let getTags = settings.load(SETTINGS_TAG);
|
|
|
|
|
Promise.all([getSettings, getTags])
|
|
|
|
|
.then(result => {
|
|
|
|
|
const [settings, tags] = result;
|
|
|
|
|
let data = { settings: settings, tags: tags };
|
|
|
|
|
resolve(data);
|
|
|
|
|
})
|
|
|
|
|
.catch(err => {
|
|
|
|
|
reject(err);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------
|
|
|
|
|