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