basic page rendering working index
This commit is contained in:
parent
f10b25e698
commit
38cfc1fc6c
5 changed files with 74 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
||||||
import * as DataEvent from '../../../src/com/events/DataEvent';
|
import * as DataEvent from '../../../src/com/events/DataEvent';
|
||||||
import Auth from '../../data/Auth';
|
import Auth from '../../data/Auth';
|
||||||
|
import Book from '../../data/Book';
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const multer = require('multer');
|
const multer = require('multer');
|
||||||
|
@ -112,10 +113,20 @@ router.post('/nav-sync', (req, res) => {
|
||||||
router.post('/publish-pages', (req, res) => {
|
router.post('/publish-pages', (req, res) => {
|
||||||
auth.authCheck(req)
|
auth.authCheck(req)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('PUBLISHING');
|
new Book()
|
||||||
|
.publish(settings.global.theme)
|
||||||
|
.then(response => {
|
||||||
res.json({
|
res.json({
|
||||||
type: DataEvent.API_RENDER_PAGES,
|
type: response.type,
|
||||||
message: 'All Pages Rendered and Published'
|
message: response.message
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
res.json({
|
||||||
|
type: DataEvent.PAGES_NOT_RENDERED,
|
||||||
|
message: 'Uh oh. Pages not rendered, sport',
|
||||||
|
error: err
|
||||||
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
|
@ -140,6 +151,7 @@ router.post('/add-avatar', avatar_upload, (req, res) => {
|
||||||
var image = path.substr(7, path.length);
|
var image = path.substr(7, path.length);
|
||||||
folks[index].avi = '/' + image;
|
folks[index].avi = '/' + image;
|
||||||
fs.writeJson('site/folks.json', folks);
|
fs.writeJson('site/folks.json', folks);
|
||||||
|
user.avi = '/' + image;
|
||||||
res.json({
|
res.json({
|
||||||
type: DataEvent.AVATAR_UPLOADED,
|
type: DataEvent.AVATAR_UPLOADED,
|
||||||
message: 'Changed avi. You look great.',
|
message: 'Changed avi. You look great.',
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
import fh from 'filehound';
|
import fh from 'filehound';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
import sanitize from 'sanitize-html';
|
||||||
import metadataParser from 'markdown-yaml-metadata-parser';
|
import metadataParser from 'markdown-yaml-metadata-parser';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import * as DataEvent from '../../src/com/events/DataEvent';
|
import * as DataEvent from '../../src/com/events/DataEvent';
|
||||||
import Navigation from './Navigation';
|
import Navigation from './Navigation';
|
||||||
|
import StringUtils from '../../src/com/utils/StringUtils';
|
||||||
const nav = new Navigation();
|
const nav = new Navigation();
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
const pug = require('pug');
|
||||||
|
const md = require('markdown-it')('commonmark');
|
||||||
|
|
||||||
export default class Pages {
|
export default class Pages {
|
||||||
//--------------------------
|
//--------------------------
|
||||||
|
@ -173,13 +177,54 @@ export default class Pages {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
publish() {
|
publish(theme) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
//let self = this;
|
|
||||||
//get pages for rendering
|
|
||||||
this.getPage()
|
this.getPage()
|
||||||
.then(pages => {
|
.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 => {
|
.catch(err => {
|
||||||
reject(err);
|
reject(err);
|
||||||
|
|
|
@ -11,8 +11,8 @@ router.get('/', function(req, res) {
|
||||||
.then(obj => {
|
.then(obj => {
|
||||||
settings = obj;
|
settings = obj;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(err => {
|
||||||
console.error(err);
|
//console.error(err);
|
||||||
});
|
});
|
||||||
loadThemes().then(themes => {
|
loadThemes().then(themes => {
|
||||||
if (req.session.user) {
|
if (req.session.user) {
|
||||||
|
@ -28,6 +28,7 @@ router.get('/', function(req, res) {
|
||||||
var textB = b.theme.name.toUpperCase();
|
var textB = b.theme.name.toUpperCase();
|
||||||
return textA < textB ? -1 : textA > textB ? 1 : 0;
|
return textA < textB ? -1 : textA > textB ? 1 : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
res.render('settings', {
|
res.render('settings', {
|
||||||
title: 'Dashboard | Settings',
|
title: 'Dashboard | Settings',
|
||||||
welcome: 'Your Settings',
|
welcome: 'Your Settings',
|
||||||
|
|
|
@ -190,7 +190,7 @@ export default class SettingsIndex {
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let r = JSON.parse(response.request['response']);
|
let r = JSON.parse(response.request['response']);
|
||||||
console.log('RESPONSE', r);
|
notify.alert(r.message, true);
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
notify.alert(err, false);
|
notify.alert(err, false);
|
||||||
|
|
|
@ -11,6 +11,8 @@ export const PAGE_ERROR = 'postError';
|
||||||
export const PAGE_ADDED = 'postAdded';
|
export const PAGE_ADDED = 'postAdded';
|
||||||
export const PAGE_UPDATED = 'postUpdated';
|
export const PAGE_UPDATED = 'postUpdated';
|
||||||
export const PAGE_DELETED = 'postImageAdded';
|
export const PAGE_DELETED = 'postImageAdded';
|
||||||
|
export const PAGES_RENDERED = 'pagesRendered';
|
||||||
|
export const PAGES_NOT_RENDERED = 'pagesNotRendered';
|
||||||
export const SETTINGS_UPDATED = 'settingsUpdated';
|
export const SETTINGS_UPDATED = 'settingsUpdated';
|
||||||
export const MENU_ADD_ITEM = 'menuAddItem';
|
export const MENU_ADD_ITEM = 'menuAddItem';
|
||||||
export const MENU_DELETE_ITEM = 'menuDeleteItem';
|
export const MENU_DELETE_ITEM = 'menuDeleteItem';
|
||||||
|
|
Loading…
Reference in a new issue