From b59f4d5f9f256fe1bf0687ec35f9d2a5be1827bb Mon Sep 17 00:00:00 2001 From: LordMathis Date: Sun, 29 Dec 2019 23:17:08 +0100 Subject: [PATCH] Get post data from mongo --- src/containers/ContentContainer.js | 2 ++ src/containers/MainContainer.js | 2 -- src/utils/scanner.js | 2 +- src/utils/serverRender.js | 2 -- src/utils/storage/file.js | 1 - src/utils/storage/mongo.js | 26 +++++++++++++++++++------- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/containers/ContentContainer.js b/src/containers/ContentContainer.js index b668c87..de7d9a8 100644 --- a/src/containers/ContentContainer.js +++ b/src/containers/ContentContainer.js @@ -18,6 +18,8 @@ export default class ContentContainer extends Component { delete window.__INITIAL_DATA__ } + console.log('ContentContainer: ', data) + this.state = { isLoading: !data, type: data[0].type, diff --git a/src/containers/MainContainer.js b/src/containers/MainContainer.js index c37229b..87cf101 100644 --- a/src/containers/MainContainer.js +++ b/src/containers/MainContainer.js @@ -18,8 +18,6 @@ export default class MainContainer extends Component { delete window.__INITIAL_DATA__ } - console.log('MainContainer', data[0].other.about) - this.state = { isLoadingBlog: !data[0].posts, isLoadingAbout: !data[0].other.about, diff --git a/src/utils/scanner.js b/src/utils/scanner.js index 59433c5..67732b4 100644 --- a/src/utils/scanner.js +++ b/src/utils/scanner.js @@ -117,7 +117,7 @@ export class Scanner { title: frontMatter.attributes.title, summary: summary, link: '/post/' + metadata.filename, - body: frontMatter.body + body: data } this.dataHolder.addPost(post) diff --git a/src/utils/serverRender.js b/src/utils/serverRender.js index 61fdffb..c74fea8 100644 --- a/src/utils/serverRender.js +++ b/src/utils/serverRender.js @@ -30,8 +30,6 @@ export class ServerRenderer { const promise = this.dataHolder.getData(req.path.split('/').pop()) promise.then((data) => { - console.log(data) - const context = [data, config] const markup = renderToString( diff --git a/src/utils/storage/file.js b/src/utils/storage/file.js index a8e9572..411b282 100644 --- a/src/utils/storage/file.js +++ b/src/utils/storage/file.js @@ -2,7 +2,6 @@ import fs from 'fs' import path from 'path' export class FileStorage { - constructor () { this.data = { posts: [], diff --git a/src/utils/storage/mongo.js b/src/utils/storage/mongo.js index 7c5a986..9883691 100644 --- a/src/utils/storage/mongo.js +++ b/src/utils/storage/mongo.js @@ -64,30 +64,42 @@ export class MongoStorage { this._getAllPosts() ]).then((res) => { data.other.about = res[0].body - data.posts = res[1] + data.posts = res[1].map((post) => { + delete post.body + return post + }) return data }) } else if (reqPath === 'resume') { return Promise.resolve({}) } else { - + return this._getPost(reqPath) } } _getOther (filename) { return new Promise((resolve, reject) => { this.Other.findOne({ filename: filename }, (err, res) => { - if (err) reject(err) - resolve(res) + err ? reject(err) : resolve(res) }) }) } _getAllPosts () { return new Promise((resolve, reject) => { - this.Post.find({}, (err, res) => { - if (err) reject(err) - resolve(res) + this.Post.find({}, (err, data) => { + err ? reject(err) : resolve(data) + }) + }) + } + + _getPost (filename) { + return new Promise((resolve, reject) => { + this.Post.findOne({ filename: filename }, (err, data) => { + err ? reject(err) : resolve({ + type: 'content', + data: data.body + }) }) }) }