From 03e8fbe82f38f73204fcea3ddc6f87dcc58aa947 Mon Sep 17 00:00:00 2001 From: Ro Date: Sun, 21 Jun 2020 13:14:09 -0700 Subject: [PATCH] index page now created as part of blog init process --- .gitignore | 3 +- brain/api/v1/auth.js | 74 +++++++++++++++++++++++++++++++++++++ brain/routes/dash/pages.js | 2 +- site/init/index-template.md | 24 ++++++++++++ 4 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 site/init/index-template.md diff --git a/.gitignore b/.gitignore index 04035d1..ea2c159 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ node_modules/ .sass-cache/ .cache/ -public/ +public/* +!public/assets/images/global content/ .ftpconfig .vscode/ diff --git a/brain/api/v1/auth.js b/brain/api/v1/auth.js index 9d887bf..b7a9c25 100644 --- a/brain/api/v1/auth.js +++ b/brain/api/v1/auth.js @@ -1,4 +1,6 @@ import * as DataEvent from '../../../src/com/events/DataEvent'; +import mdparser from 'markdown-yaml-metadata-parser'; +const uuidv4 = require('uuid/v4'); const express = require('express'); const router = express.Router(); const bcrypt = require('bcrypt'); @@ -141,6 +143,78 @@ router.post('/init', function (req, res) { fs.writeJson('site/tags.json', { tags: [] }); + //set up index file as first page + + fs.readFile('site/init/index-template.md', { encoding: 'utf8' }).then(file => { + let index = mdparser(file); + let data = index.metadata; + data.uuid = uuidv4(); + data.path = moment().format('YYYY') + '/' + moment().format('MM'); + data.author = body.new_member_handle; + data.created = moment(Date.now()).format(); + data.updated = moment(Date.now()).format(); + + var init = + '---\n' + + 'id: ' + + data.id + + '\n' + + 'uuid: ' + + data.uuid + + '\n' + + 'title: ' + + data.title + + '\n' + + 'feature: ' + + data.feature + + '\n' + + 'path: ' + + moment(Date.now()).format('YYYY') + + '/' + + moment(Date.now()).format('MM') + + '\n' + + 'layout: ' + + 'index' + + '\n' + + 'tags: ' + + data.tags + + '\n' + + 'author: ' + + body.new_member_handle + + '\n' + + 'created: ' + + moment(Date.now()).format() + + '\n' + + 'updated: ' + + moment(Date.now()).format() + + '\n' + + 'deleted: ' + + 'false' + + '\n' + + 'menu: ' + + data.menu + + '\n' + + 'featured: ' + + data.featured + + '\n' + + 'published: ' + + data.published + + '\n' + + 'slug: ' + + data.slug + + '\n' + + '---\n' + + index.content; + + fs.writeFile('content/pages/index.md', init) + .then(() => { + console.log('index file created'); + }) + .catch(err => { + console.log('ERROR', err); + }); + }); + res.json({ type: DataEvent.API_INIT_GOOD, message: 'All Set Up' diff --git a/brain/routes/dash/pages.js b/brain/routes/dash/pages.js index e2fe339..2e33bfb 100644 --- a/brain/routes/dash/pages.js +++ b/brain/routes/dash/pages.js @@ -92,7 +92,7 @@ router.get('/list/:filter?/:page?', function (req, res) { router.get('/add/new', function (req, res) { if (req.session.user) { //need to grab a few copy of settings for the lastest index - fs.readJSON('site/settings.jso') + fs.readJSON('site/settings.json') .then(config => { res.render('page-edit', { id: config.library_stats.current_index, diff --git a/site/init/index-template.md b/site/init/index-template.md new file mode 100644 index 0000000..55beedb --- /dev/null +++ b/site/init/index-template.md @@ -0,0 +1,24 @@ +--- +id: 1 +uuid: +title: This is the Start +feature: /assets/images/global/default-bg.jpg +path: +layout: index +tags: start +author: +created: +updated: +deleted: false +menu: false +featured: false +published: false +slug: index +--- +# F**k Yes + +You're up and running here are a few notes to get you started. + +One more layout check. + +This page should stay on the root of pages