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__ delete window.__INITIAL_DATA__
} }
console.log('ContentContainer: ', data)
this.state = { this.state = {
isLoading: !data, isLoading: !data,
type: data[0].type, type: data[0].type,

View File

@ -18,8 +18,6 @@ export default class MainContainer extends Component {
delete window.__INITIAL_DATA__ delete window.__INITIAL_DATA__
} }
console.log('MainContainer', data[0].other.about)
this.state = { this.state = {
isLoadingBlog: !data[0].posts, isLoadingBlog: !data[0].posts,
isLoadingAbout: !data[0].other.about, isLoadingAbout: !data[0].other.about,

View File

@ -117,7 +117,7 @@ export class Scanner {
title: frontMatter.attributes.title, title: frontMatter.attributes.title,
summary: summary, summary: summary,
link: '/post/' + metadata.filename, link: '/post/' + metadata.filename,
body: frontMatter.body body: data
} }
this.dataHolder.addPost(post) this.dataHolder.addPost(post)

View File

@ -30,8 +30,6 @@ export class ServerRenderer {
const promise = this.dataHolder.getData(req.path.split('/').pop()) const promise = this.dataHolder.getData(req.path.split('/').pop())
promise.then((data) => { promise.then((data) => {
console.log(data)
const context = [data, config] const context = [data, config]
const markup = renderToString( const markup = renderToString(
<Router location={req.url} context={{ context }}> <Router location={req.url} context={{ context }}>

View File

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

View File

@ -64,30 +64,42 @@ export class MongoStorage {
this._getAllPosts() this._getAllPosts()
]).then((res) => { ]).then((res) => {
data.other.about = res[0].body data.other.about = res[0].body
data.posts = res[1] data.posts = res[1].map((post) => {
delete post.body
return post
})
return data return data
}) })
} else if (reqPath === 'resume') { } else if (reqPath === 'resume') {
return Promise.resolve({}) return Promise.resolve({})
} else { } else {
return this._getPost(reqPath)
} }
} }
_getOther (filename) { _getOther (filename) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.Other.findOne({ filename: filename }, (err, res) => { this.Other.findOne({ filename: filename }, (err, res) => {
if (err) reject(err) err ? reject(err) : resolve(res)
resolve(res)
}) })
}) })
} }
_getAllPosts () { _getAllPosts () {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.Post.find({}, (err, res) => { this.Post.find({}, (err, data) => {
if (err) reject(err) err ? reject(err) : resolve(data)
resolve(res) })
})
}
_getPost (filename) {
return new Promise((resolve, reject) => {
this.Post.findOne({ filename: filename }, (err, data) => {
err ? reject(err) : resolve({
type: 'content',
data: data.body
})
}) })
}) })
} }