2019-11-23 19:30:34 +01:00
|
|
|
import Book from '../../data/Book';
|
2019-11-24 01:09:37 +01:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
|
|
|
const hljs = require('highlight.js/lib/highlight');
|
|
|
|
const hljs_md = require('highlight.js/lib/languages/markdown');
|
2018-11-11 21:22:01 +01:00
|
|
|
hljs.registerLanguage('markdown', hljs_md);
|
2019-11-24 01:09:37 +01:00
|
|
|
const moment = require('moment');
|
2019-11-23 19:30:34 +01:00
|
|
|
const book = new Book();
|
2018-11-11 21:22:01 +01:00
|
|
|
//--------------------------
|
|
|
|
// POSTS
|
|
|
|
//--------------------------
|
2019-03-02 03:51:35 +01:00
|
|
|
router.get('/list/:filter?/:page?', function(req, res) {
|
2019-02-27 17:17:51 +01:00
|
|
|
var pageNum = req.params.page;
|
2019-03-01 23:48:05 +01:00
|
|
|
var filter = req.params.filter;
|
2019-02-27 17:17:51 +01:00
|
|
|
if (pageNum == '' || pageNum == null) pageNum = 1;
|
2019-03-01 23:48:05 +01:00
|
|
|
if (filter == '' || filter == null) filter = 'all';
|
2019-11-16 18:10:05 +01:00
|
|
|
/*
|
2019-02-27 17:17:51 +01:00
|
|
|
if (req.session.user) {
|
2019-11-10 21:07:29 +01:00
|
|
|
|
2019-02-27 17:17:51 +01:00
|
|
|
.then(() => {
|
|
|
|
//console.log(value);
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
//next(err);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
2019-11-16 18:10:05 +01:00
|
|
|
*/
|
2018-11-11 21:22:01 +01:00
|
|
|
});
|
|
|
|
//--------------------------
|
|
|
|
// BLOG POST ADD DISPLAY
|
|
|
|
//--------------------------
|
2019-02-27 17:17:51 +01:00
|
|
|
router.get('/add/new', function(req, res) {
|
|
|
|
if (req.session.user) {
|
|
|
|
res.render('dash/post-edit', {
|
2019-02-27 22:09:39 +01:00
|
|
|
title: 'Dashboard New Post',
|
|
|
|
user_status: true,
|
|
|
|
welcome: 'New Post',
|
2019-02-27 17:17:51 +01:00
|
|
|
mode: 'admin',
|
2019-11-24 01:09:37 +01:00
|
|
|
date: '',
|
2019-02-27 17:17:51 +01:00
|
|
|
status: ['false', 'false', 'false'],
|
|
|
|
edit: false
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
2018-11-11 21:22:01 +01:00
|
|
|
});
|
|
|
|
//--------------------------
|
|
|
|
// BLOG POST EDIT DISPLAY
|
|
|
|
//--------------------------
|
2019-02-27 17:17:51 +01:00
|
|
|
router.get('/edit/:id', function(req, res) {
|
2019-11-23 19:30:34 +01:00
|
|
|
var id = req.params.id;
|
2019-02-27 17:17:51 +01:00
|
|
|
if (req.session.user) {
|
2019-11-23 19:30:34 +01:00
|
|
|
book.getPage(id)
|
|
|
|
.then(page => {
|
|
|
|
let pretty = hljs.highlight('markdown', page.content).value;
|
|
|
|
res.render('page-edit', {
|
|
|
|
id: page.metadata.id,
|
|
|
|
title: 'Edit Page',
|
|
|
|
user_status: true,
|
|
|
|
welcome: 'Edit Page',
|
|
|
|
mode: 'admin',
|
|
|
|
page: page.metadata,
|
2019-11-24 01:09:37 +01:00
|
|
|
date: moment(page.metadata.created).format('YYYY MMM DD'),
|
2019-11-23 19:30:34 +01:00
|
|
|
colored: pretty,
|
|
|
|
feature: page.metadata.feature,
|
|
|
|
status: [
|
|
|
|
String(true),
|
|
|
|
String(page.metadata.featured),
|
|
|
|
String(page.metadata.published)
|
|
|
|
],
|
|
|
|
edit: true
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch(err => {
|
|
|
|
res.json({ type: err });
|
|
|
|
});
|
2019-11-16 18:10:05 +01:00
|
|
|
} else {
|
2019-02-27 17:17:51 +01:00
|
|
|
res.redirect('/@/dashboard');
|
|
|
|
}
|
2018-11-11 21:22:01 +01:00
|
|
|
});
|
2019-02-27 17:17:51 +01:00
|
|
|
module.exports = router;
|