From f6fc242d9cb4faf3c2c6fe087ce93051804c4ed2 Mon Sep 17 00:00:00 2001 From: Ro Date: Tue, 26 May 2020 16:02:21 -0700 Subject: [PATCH] added markdown page organization and path variable to md meta for orgainzied html rendering --- brain/data/Book.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/brain/data/Book.js b/brain/data/Book.js index 132b65b..160dffe 100644 --- a/brain/data/Book.js +++ b/brain/data/Book.js @@ -75,6 +75,14 @@ export default class Book { case DataEvent.API_PAGE_CREATE: case DataEvent.API_PAGE_WRITE: var layout = 'page'; + var path = ''; + fs.ensureDir( + 'content/pages/' + + moment(body.created).format('YYYY') + + '/' + + moment(body.created).format('MM') + + '/' + ); if (body.layout !== 'page') layout = body.layout; if (body.layout === null || body.layout === 'null') layout = 'page'; var pageWrite = @@ -91,6 +99,11 @@ export default class Book { 'feature: ' + body.feature + '\n' + + 'path: ' + + moment(body.created).format('YYYY') + + '/' + + moment().format('MM') + + '\n' + 'layout: ' + layout + '\n' + @@ -123,7 +136,17 @@ export default class Book { '\n' + '---\n' + body.content; - fs.writeFile('content/pages/' + body.slug + '.md', pageWrite, err => { + layout === 'index' + ? (path = 'content/pages/' + body.slug + '.md') + : (path = + 'content/pages/' + + moment(body.created).format('YYYY') + + '/' + + moment(body.created).format('MM') + + '/' + + body.slug + + '.md'); + fs.writeFile(path, pageWrite, err => { // throws an error, you could also catch it here if (err) {