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) {