Get post data from mongo
This commit is contained in:
parent
f1c479c146
commit
b59f4d5f9f
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 }}>
|
||||
|
|
|
@ -2,7 +2,6 @@ import fs from 'fs'
|
|||
import path from 'path'
|
||||
|
||||
export class FileStorage {
|
||||
|
||||
constructor () {
|
||||
this.data = {
|
||||
posts: [],
|
||||
|
|
|
@ -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
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue