basic page rendering working index

pull/20/head
Ro 5 years ago
parent f10b25e698
commit 38cfc1fc6c

@ -1,5 +1,6 @@
import * as DataEvent from '../../../src/com/events/DataEvent';
import Auth from '../../data/Auth';
import Book from '../../data/Book';
const express = require('express');
const router = express.Router();
const multer = require('multer');
@ -112,10 +113,20 @@ router.post('/nav-sync', (req, res) => {
router.post('/publish-pages', (req, res) => {
auth.authCheck(req)
.then(() => {
console.log('PUBLISHING');
new Book()
.publish(settings.global.theme)
.then(response => {
res.json({
type: DataEvent.API_RENDER_PAGES,
message: 'All Pages Rendered and Published'
type: response.type,
message: response.message
});
})
.catch(err => {
res.json({
type: DataEvent.PAGES_NOT_RENDERED,
message: 'Uh oh. Pages not rendered, sport',
error: err
});
});
})
.catch(err => {
@ -140,6 +151,7 @@ router.post('/add-avatar', avatar_upload, (req, res) => {
var image = path.substr(7, path.length);
folks[index].avi = '/' + image;
fs.writeJson('site/folks.json', folks);
user.avi = '/' + image;
res.json({
type: DataEvent.AVATAR_UPLOADED,
message: 'Changed avi. You look great.',

@ -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);

@ -11,8 +11,8 @@ router.get('/', function(req, res) {
.then(obj => {
settings = obj;
})
.catch(() => {
console.error(err);
.catch(err => {
//console.error(err);
});
loadThemes().then(themes => {
if (req.session.user) {
@ -28,6 +28,7 @@ router.get('/', function(req, res) {
var textB = b.theme.name.toUpperCase();
return textA < textB ? -1 : textA > textB ? 1 : 0;
});
res.render('settings', {
title: 'Dashboard | Settings',
welcome: 'Your Settings',

@ -190,7 +190,7 @@ export default class SettingsIndex {
)
.then(response => {
let r = JSON.parse(response.request['response']);
console.log('RESPONSE', r);
notify.alert(r.message, true);
})
.catch(err => {
notify.alert(err, false);

@ -11,6 +11,8 @@ export const PAGE_ERROR = 'postError';
export const PAGE_ADDED = 'postAdded';
export const PAGE_UPDATED = 'postUpdated';
export const PAGE_DELETED = 'postImageAdded';
export const PAGES_RENDERED = 'pagesRendered';
export const PAGES_NOT_RENDERED = 'pagesNotRendered';
export const SETTINGS_UPDATED = 'settingsUpdated';
export const MENU_ADD_ITEM = 'menuAddItem';
export const MENU_DELETE_ITEM = 'menuDeleteItem';

Loading…
Cancel
Save