From 161f441b842285685fbe73a2e7c0b94aa592ac52 Mon Sep 17 00:00:00 2001 From: Ro Date: Thu, 21 May 2020 21:18:32 -0700 Subject: [PATCH] made separate file for tags, fixed config caching error when creating new post --- .gitignore | 1 + brain/data/Render.js | 3 ++- brain/data/Settings.js | 4 ++-- brain/routes/dash/pages.js | 38 +++++++++++++++++++++++++------------ src/styles/main/_posts.styl | 4 ++-- 5 files changed, 33 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index d26b4fe..191fa6a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ config.development.json site/settings.json site/folks.json site/pages.json +site/tags.json brain/models/_backup/ /_maintenance/ *.DS_Store diff --git a/brain/data/Render.js b/brain/data/Render.js index b238ca6..0b36543 100644 --- a/brain/data/Render.js +++ b/brain/data/Render.js @@ -3,6 +3,7 @@ import StringUtils from '../../src/com/utils/StringUtils'; 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'); @@ -73,7 +74,7 @@ export default class Render { } publishTags(pages) { return new Promise((resolve, reject) => { - let tags = config.tags; + let tags = tags_list.tags; let renderList = []; for (let index = 0; index < tags.length; index++) { let tag = tags[index]; diff --git a/brain/data/Settings.js b/brain/data/Settings.js index 0a4be6e..c7a4fbd 100644 --- a/brain/data/Settings.js +++ b/brain/data/Settings.js @@ -1,6 +1,6 @@ import * as DataEvent from '../../src/com/events/DataEvent'; import fs from 'fs-extra'; -const config = require('../../site/settings.json'); +const config = require('../../site/tags.json'); const _ = require('lodash'); export default class Settings { @@ -15,7 +15,7 @@ export default class Settings { return new Promise((resolve, reject) => { if (!_.isEqual(config.tags, tags)) { config.tags = tags; - fs.writeJson('site/settings.json', config) + fs.writeJson('site/tags.json', config) .then(() => { let response = { type: DataEvent.SETTINGS_UPDATED, diff --git a/brain/routes/dash/pages.js b/brain/routes/dash/pages.js index 1539ed2..bf53dd6 100644 --- a/brain/routes/dash/pages.js +++ b/brain/routes/dash/pages.js @@ -4,7 +4,7 @@ const router = express.Router(); const moment = require('moment'); const book = new Book(); const uuidv4 = require('uuid/v4'); -const settings = require('../../../site/settings.json'); +const fs = require('fs-extra'); //-------------------------- // POSTS //-------------------------- @@ -91,17 +91,31 @@ router.get('/list/:filter?/:page?', function (req, res) { //-------------------------- router.get('/add/new', function (req, res) { if (req.session.user) { - res.render('page-edit', { - id: settings.library_stats.current_index, - uuid: uuidv4(), - title: 'Add New Page', - user_status: true, - welcome: 'Add New Page', - date: moment(Date.now()).format('YYYY MMM DD'), - page: [], - rawDate: moment(Date.now()).format(), - status: ['false', 'false', 'false'], - edit: false + //need to grab a few copy of settings for the lastest index + fs.readFile('site/settings.json', 'utf8', (err, json) => { + if (err) { + // TODO: add error page + //console.log('Error reading file from disk:', err); + return; + } + try { + let config = JSON.parse(json); + res.render('page-edit', { + id: config.library_stats.current_index, + uuid: uuidv4(), + title: 'Add New Page', + user_status: true, + welcome: 'Add New Page', + date: moment(Date.now()).format('YYYY MMM DD'), + page: [], + rawDate: moment(Date.now()).format(), + status: ['false', 'false', 'false'], + edit: false + }); + } catch (err) { + //add error page + console.log('ERROR', err); + } }); } else { res.redirect('/@/dashboard'); diff --git a/src/styles/main/_posts.styl b/src/styles/main/_posts.styl index 1efc8d1..3afd039 100644 --- a/src/styles/main/_posts.styl +++ b/src/styles/main/_posts.styl @@ -85,7 +85,7 @@ background $primary - 4% font-family $baseType width 97.6% - height 140px + height 80px font-size 1.5em color $white padding 5px @@ -147,7 +147,7 @@ background $primary - 4% font-family $baseType width 97.6% - height 140px + height 80px color $secondary padding 5px margin 0 0 5px 0