Prepare for mongodb storage backend
This commit is contained in:
parent
1d621ea239
commit
b53a7c3509
|
@ -1,6 +1,7 @@
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import jsonfile from 'jsonfile'
|
import jsonfile from 'jsonfile'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import mongoose from 'mongoose'
|
||||||
|
|
||||||
export class DataHolder {
|
export class DataHolder {
|
||||||
constructor (config) {
|
constructor (config) {
|
||||||
|
@ -11,6 +12,25 @@ export class DataHolder {
|
||||||
posts: [],
|
posts: [],
|
||||||
other: {}
|
other: {}
|
||||||
}
|
}
|
||||||
|
} else if (this.config.storage === 'mongo') {
|
||||||
|
mongoose.connect(config.mongourl, { useNewUrlParser: true })
|
||||||
|
this.db = mongoose.connection
|
||||||
|
this.db.on('error', (error) => console.error(`[DataHolder] ${error}`))
|
||||||
|
this.db.once('open', () => console.log('[DataHolder] Connected to database'))
|
||||||
|
|
||||||
|
this.Post = mongoose.model('Post', {
|
||||||
|
filename: String,
|
||||||
|
published: String,
|
||||||
|
title: String,
|
||||||
|
summary: String,
|
||||||
|
link: String,
|
||||||
|
body: String
|
||||||
|
})
|
||||||
|
|
||||||
|
this.Other = mongoose.model('Other', {
|
||||||
|
filename: String,
|
||||||
|
body: String
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +72,7 @@ export class DataHolder {
|
||||||
}
|
}
|
||||||
|
|
||||||
addPost (post) {
|
addPost (post) {
|
||||||
|
delete post.body
|
||||||
this.data.posts.push(post)
|
this.data.posts.push(post)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,8 @@ export class Scanner {
|
||||||
filename: metadata.filename,
|
filename: metadata.filename,
|
||||||
title: frontMatter.attributes.title,
|
title: frontMatter.attributes.title,
|
||||||
summary: summary,
|
summary: summary,
|
||||||
link: '/post/' + metadata.filename
|
link: '/post/' + metadata.filename,
|
||||||
|
body: frontMatter.body
|
||||||
}
|
}
|
||||||
|
|
||||||
this.dataHolder.addPost(post)
|
this.dataHolder.addPost(post)
|
||||||
|
|
Loading…
Reference in New Issue