From d536871fd420d8a93c370d970b9b757965186f23 Mon Sep 17 00:00:00 2001 From: Ro Date: Sat, 23 Nov 2019 10:30:34 -0800 Subject: [PATCH] added pages config json(may not need), synced editor to markdown metadata, resolved new asset dependency paths --- .gitignore | 5 +-- brain/api/v1/auth.js | 2 +- brain/api/v1/pages.js | 2 +- brain/app.js | 4 +-- brain/data/{Pages.js => Book.js} | 12 +++++-- brain/routes/dash/index.js | 9 ++--- brain/routes/dash/{posts.js => pages.js} | 34 +++++++++++++++++++ brain/views/{post-edit.pug => page-edit.pug} | 20 +++++------ .../views/{posts-index.pug => page-index.pug} | 0 brain/views/partials/editor.pug | 14 ++++---- brain/views/partials/front.pug | 2 +- config/config.json.example | 30 ---------------- {config => site}/site-settings.json.example | 0 13 files changed, 74 insertions(+), 60 deletions(-) rename brain/data/{Pages.js => Book.js} (79%) rename brain/routes/dash/{posts.js => pages.js} (64%) rename brain/views/{post-edit.pug => page-edit.pug} (85%) rename brain/views/{posts-index.pug => page-index.pug} (100%) delete mode 100644 config/config.json.example rename {config => site}/site-settings.json.example (100%) diff --git a/.gitignore b/.gitignore index e32f29f..9352e9d 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,9 @@ content/ config.development.json *.swp /config.json -config/config.json -config/folks.json +site/settings.json +site/folks.json +site/pages.json brain/models/_backup/ /_maintenance/ *.DS_Store diff --git a/brain/api/v1/auth.js b/brain/api/v1/auth.js index 219c390..1d2f336 100644 --- a/brain/api/v1/auth.js +++ b/brain/api/v1/auth.js @@ -23,7 +23,7 @@ router.get('/', function(req, res) { * Login Member and return token */ router.post('/login', function(req, res) { - fs.readJson('config/folks.json').then(folks => { + fs.readJson('site/folks.json').then(folks => { let found = _.find(folks, { handle: req.body.handle }); if (found) { if (!isValidPassword(found, req.body.password)) { diff --git a/brain/api/v1/pages.js b/brain/api/v1/pages.js index 06d1df9..13dee50 100644 --- a/brain/api/v1/pages.js +++ b/brain/api/v1/pages.js @@ -1,5 +1,5 @@ import DateUtils from '../../../src/com/utils/DateUtils'; -import Pages from '../../data/Pages'; +import Pages from '../../data/Book'; import StringUtils from '../../../src/com/utils/StringUtils'; import * as DataEvent from '../../../src/com/events/DataEvent'; import sanitize from 'sanitize-html'; diff --git a/brain/app.js b/brain/app.js index 2492f9a..ab9c639 100644 --- a/brain/app.js +++ b/brain/app.js @@ -43,7 +43,7 @@ app.use(flash()); //sections //var front = require('./routes/front/index')(session); var dash = require('./routes/dash/index'); -var postDashboard = require('./routes/dash/posts'); +var page = require('./routes/dash/pages'); //var settingsDashboard = require('./routes/dash/settings'); //var navDashboard = require('./routes/dash/nav'); //api @@ -60,7 +60,7 @@ app.use('/api/v1/auth', auth); // PAGES //app.use('/', front); app.use('/@/dashboard', dash); -app.use('/@/dashboard/posts', postDashboard); +app.use('/@/dashboard/page', page); //app.use('/@/dashboard/settings', settingsDashboard); //app.use('/@/dashboard/navigation', navDashboard); //app.use('/mailer', mailer); diff --git a/brain/data/Pages.js b/brain/data/Book.js similarity index 79% rename from brain/data/Pages.js rename to brain/data/Book.js index e6c2a53..43d9381 100644 --- a/brain/data/Pages.js +++ b/brain/data/Book.js @@ -1,6 +1,7 @@ import fh from 'filehound'; import fs from 'fs-extra'; import metadataParser from 'markdown-yaml-metadata-parser'; +import _ from 'lodash'; export default class Pages { //-------------------------- @@ -12,7 +13,7 @@ export default class Pages { //-------------------------- start() {} - grab(id) { + getPage(id) { return new Promise((resolve, reject) => { fh.create() .paths('content/pages') @@ -25,13 +26,20 @@ export default class Pages { pages.push(metadataParser(file)); }); } + if (id === null || id === null || id === undefined) { setTimeout(() => { //TODO: Duct tape solution until something better created resolve(pages); }, 100); } else { - // find specific pages + setTimeout(() => { + //TODO: Duct tape solution until something better created + let page = _.find(pages, list => { + return list.metadata.uuid === id; + }); + resolve(page); + }, 100); } }) .catch(err => { diff --git a/brain/routes/dash/index.js b/brain/routes/dash/index.js index 67cc41b..6fcfa81 100644 --- a/brain/routes/dash/index.js +++ b/brain/routes/dash/index.js @@ -1,14 +1,15 @@ -import Pages from '../../data/Pages'; +import Book from '../../data/Book'; const express = require('express'); const router = express.Router(); -const settings = require('../../../config/site-settings.json'); +const settings = require('../../../site/settings.json'); //-------------------------- // Index //-------------------------- router.get('/', function(req, res) { - let pages = new Pages(); - pages.grab().then(result => { + let book = new Book(); + book.getPage().then(result => { + result.sort((a, b) => parseFloat(b.metadata.id) - parseFloat(a.metadata.id)); let pageData = []; if (req.session.user) { pageData = { title: settings.title, status: true, pages: result }; diff --git a/brain/routes/dash/posts.js b/brain/routes/dash/pages.js similarity index 64% rename from brain/routes/dash/posts.js rename to brain/routes/dash/pages.js index 32bc8d1..38b70f2 100644 --- a/brain/routes/dash/posts.js +++ b/brain/routes/dash/pages.js @@ -1,10 +1,12 @@ import DateUtils from '../../../src/com/utils/DateUtils'; +import Book from '../../data/Book'; var express = require('express'); var router = express.Router(); var hljs = require('highlight.js/lib/highlight'); var hljs_md = require('highlight.js/lib/languages/markdown'); hljs.registerLanguage('markdown', hljs_md); const dateUtils = new DateUtils(); +const book = new Book(); //-------------------------- // POSTS //-------------------------- @@ -54,7 +56,39 @@ router.get('/add/new', function(req, res) { // BLOG POST EDIT DISPLAY //-------------------------- router.get('/edit/:id', function(req, res) { + var id = req.params.id; if (req.session.user) { + book.getPage(id) + .then(page => { + let pretty = hljs.highlight('markdown', page.content).value; + let sexydate = + dateUtils.getDate('year', page.metadata.created) + + '-' + + dateUtils.getDate('month', page.metadata.created) + + '-' + + dateUtils.getDate('day', page.metadata.created); + + res.render('page-edit', { + id: page.metadata.id, + title: 'Edit Page', + user_status: true, + welcome: 'Edit Page', + mode: 'admin', + page: page.metadata, + date: sexydate, + 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 }); + }); } else { res.redirect('/@/dashboard'); } diff --git a/brain/views/post-edit.pug b/brain/views/page-edit.pug similarity index 85% rename from brain/views/post-edit.pug rename to brain/views/page-edit.pug index e2a2b82..83e959e 100644 --- a/brain/views/post-edit.pug +++ b/brain/views/page-edit.pug @@ -10,10 +10,10 @@ block main-content -var post_status = ['false', 'false', 'false',] if(edit) - -post_title = post.title - -post_plaintext = post.plaintext - -post_feature = feature - -post_tags = post.tags + -post_title = page.title + -post_plaintext = page.plaintext + -post_feature = page.feature + -post_tags = page.tags -post_date = date -post_status = status @@ -32,7 +32,7 @@ block main-content #featured-new-image-btn button#new-feature-upload svg#new-feature-upload(viewBox="0 0 20 20" class="icons") - use(xlink:href='/dash/assets/images/sprite.svg#entypo-image-inverted') + use(xlink:href='/assets/images/global/sprite.svg#entypo-image-inverted') #featured-image-drop img(src=post_feature) #post-header.columns @@ -41,21 +41,21 @@ block main-content =post_title #calendar-icon svg(viewBox="0 0 20 20" class="icons") - use(xlink:href='/dash/assets/images/sprite.svg#entypo-calendar') + use(xlink:href='/assets/images/global/sprite.svg#entypo-calendar') input(id="post-date" type="text" value=post_date) #post-options button#option-page.option-inactive.post-option-btn(data-active= status[0]) svg#option-page-icon(viewBox="0 0 20 20" class="icons") - use#option-page-icon(xlink:href='/dash/assets/images/sprite.svg#entypo-pin') + use#option-page-icon(xlink:href='/assets/images/global/sprite.svg#entypo-pin') button#option-feature.option-inactive.post-option-btn(data-active= status[1]) svg#option-feature-icon(viewBox="0 0 20 20" class="icons") - use#option-feature-icon(xlink:href='/dash/assets/images/sprite.svg#entypo-star') + use#option-feature-icon(xlink:href='/assets/images/global/sprite.svg#entypo-star') button#option-published.option-inactive.post-option-btn(data-active= status[2]) svg#option-published-icon(viewBox="0 0 20 20" class="icons") - use#option-published-icon(xlink:href='/dash/assets/images/sprite.svg#entypo-globe') + use#option-published-icon(xlink:href='/assets/images/global/sprite.svg#entypo-globe') button#option-preview.option-inactive(data-active="false") svg#option-preview-icon(viewBox="0 0 20 20" class="icons") - use#option-preview-icon(xlink:href='/dash/assets/images/sprite.svg#entypo-eye') + use#option-preview-icon(xlink:href='/assets/images/global/sprite.svg#entypo-eye') #post-meta.column textarea(id='post_tags' type='text', name='post_tags' class='form-control', placeholder='tags [comma seperated]', autofocus) =post_tags diff --git a/brain/views/posts-index.pug b/brain/views/page-index.pug similarity index 100% rename from brain/views/posts-index.pug rename to brain/views/page-index.pug diff --git a/brain/views/partials/editor.pug b/brain/views/partials/editor.pug index 4db0c58..6f520ef 100644 --- a/brain/views/partials/editor.pug +++ b/brain/views/partials/editor.pug @@ -7,7 +7,7 @@ | S button#edit-link.content-editor-btn-icon.editor-button(title="insert link") svg#edit-link(viewBox="0 0 20 20" class="icons") - use#edit-link(xlink:href='/dash/assets/images/sprite.svg#entypo-link') + use#edit-link(xlink:href='/assets/images/global/sprite.svg#entypo-link') button#edit-header1.content-editor-btn-text.editor-button(title="header 1") | H1 button#edit-header2.content-editor-btn-text.editor-button(title="header 2") @@ -16,19 +16,19 @@ | H3 button#edit-image.content-editor-btn-icon.editor-button(title='insert image') svg#edit-image(viewBox="0 0 20 20" class="icons") - use#edit-image(xlink:href='/dash/assets/images/sprite.svg#entypo-image') + use#edit-image(xlink:href='/assets/images/global/sprite.svg#entypo-image') if(edit) - button#edit-update.post-sumbit-btn.submit-start.editor-button(data-action='blog-update' data-id=post.id type='submit') + button#edit-update.post-sumbit-btn.submit-start.editor-button(data-action='blog-update' data-id=page.id type='submit') svg#submit-update(viewBox="0 0 20 20" class="icons") - use#submit-update(xlink:href='/dash/assets/images/sprite.svg#entypo-save' data-action='blog-update' data-id=post.id) + use#submit-update(xlink:href='/assets/images/global/sprite.svg#entypo-save' data-action='blog-update' data-id=page.id) svg#submit-good.icon-hide(viewBox="0 0 20 20" class="icons") - use(xlink:href='/dash/assets/images/sprite.svg#entypo-thumbs-up') + use(xlink:href='/assets/images/global/sprite.svg#entypo-thumbs-up') svg#submit-error.icon-hide(viewBox="0 0 20 20" class="icons") - use(xlink:href='/dash/assets/images/sprite.svg#entypo-thumbs-down') + use(xlink:href='/assets/images/global/sprite.svg#entypo-thumbs-down') button#edit-delete.content-editor-btn-icon.editor-button.submit-delete(for="post-delete" title='delete post') svg#edit-delete(viewBox="0 0 20 20" class="icons") - use#edit-delete(xlink:href='/dash/assets/images/sprite.svg#entypo-cross') + use#edit-delete(xlink:href='/assets/images/global/sprite.svg#entypo-cross') else button#edit-save.post-sumbit-btn.submit-start.editor-button(data-action='blog-add' type='submit') svg#submit-save(viewBox="0 0 20 20" class="icons") diff --git a/brain/views/partials/front.pug b/brain/views/partials/front.pug index c6b0395..99f4c67 100644 --- a/brain/views/partials/front.pug +++ b/brain/views/partials/front.pug @@ -13,7 +13,7 @@ label this is empty else - for ( index; index < pages.length; index++) - a.post-link(href="/@/dashboard/posts/edit/"+pages[index].metadata.uuid id=pages[index].metadata.uuid style="background:url("+pages[index].metadata.feature+") no-repeat center center / cover") + a.post-link(href="/@/dashboard/page/edit/"+pages[index].metadata.uuid id=pages[index].metadata.uuid style="background:url("+pages[index].metadata.feature+") no-repeat center center / cover") div label= pages[index].metadata.title span= pages[index].metadata.created diff --git a/config/config.json.example b/config/config.json.example deleted file mode 100644 index 5f6b2d8..0000000 --- a/config/config.json.example +++ /dev/null @@ -1,30 +0,0 @@ -{ - "url": "DOMAIN_URL", - "theme": "default", - "development": { - "database": "DATABASE", - "user": "DATABASE_USER", - "password": "DATABASE_PASS", - "dialect": "postgres", - "host": "localhost", - "operatorsAliases": false, - "pool": { - "max": 9, - "min": 0, - "idle": 10000 - } - }, - "production": { - "database": "DATABASE", - "user": "DATABASE_USER", - "password": "DATABASE_PASS", - "operatorsAliases": false, - "host": "localhost", - "dialect": "postgres", - "pool": { - "max": 9, - "min": 0, - "idle": 10000 - } - } -} \ No newline at end of file diff --git a/config/site-settings.json.example b/site/site-settings.json.example similarity index 100% rename from config/site-settings.json.example rename to site/site-settings.json.example