Get post data from mongo

This commit is contained in:
LordMathis 2019-12-29 23:17:08 +01:00
parent f1c479c146
commit b59f4d5f9f
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
6 changed files with 22 additions and 13 deletions

View File

@ -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,

View File

@ -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,

View File

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

View File

@ -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(
<Router location={req.url} context={{ context }}>

View File

@ -2,7 +2,6 @@ import fs from 'fs'
import path from 'path'
export class FileStorage {
constructor () {
this.data = {
posts: [],

View File

@ -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
})
})
})
}