Skip to content

Commit

Permalink
Temporary fs fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitk05 committed Jul 8, 2019
1 parent f3041a0 commit 386e498
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions lib/resources/fs/index.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
const _ = require('lodash')
const environment = require('./../../config').env
const markdown = require('markdown').markdown
const fs = require('fs')
// const _ = require('lodash')
// const environment = require('./../../config').env
// const markdown = require('markdown').markdown
// const fs = require('fs')

module.exports = {
get(from, size) {
const rootPath = __dirname.split('/lib/resources/fs')[0]
let contentPath = _.get(environment(), 'source.config.contentPath')
if (!contentPath) reject('Could not read content directory.')
if (contentPath[0] !== '/') contentPath = '/' + contentPath
return new Promise((resolve, reject) => {
let blogs = []
fs.readdir(rootPath + contentPath, async (err, files) => {
if (err) reject('Could not read content directory.')
for (let i = 0; i < files.length; i++) {
let f = files[i]
blogs.push(await new Promise(res => fs.readFile(rootPath + contentPath + '/' + f, 'utf-8', (err, content) => {
if (err) reject('Could not read file.', err)
let blog = {}
blog.title = f.split('.')[0]
blog.content = f.split('.')[1] === 'md' ? markdown.toHTML(content) : content
res(blog)
})))
}
resolve(blogs)
})
})
}
}
// module.exports = {
// get(from, size) {
// const rootPath = __dirname.split('/lib/resources/fs')[0]
// let contentPath = _.get(environment(), 'source.config.contentPath')
// if (!contentPath) reject('Could not read content directory.')
// if (contentPath[0] !== '/') contentPath = '/' + contentPath
// return new Promise((resolve, reject) => {
// let blogs = []
// fs.readdir(rootPath + contentPath, async (err, files) => {
// if (err) reject('Could not read content directory.')
// for (let i = 0; i < files.length; i++) {
// let f = files[i]
// blogs.push(await new Promise(res => fs.readFile(rootPath + contentPath + '/' + f, 'utf-8', (err, content) => {
// if (err) reject('Could not read file.', err)
// let blog = {}
// blog.title = f.split('.')[0]
// blog.content = f.split('.')[1] === 'md' ? markdown.toHTML(content) : content
// res(blog)
// })))
// }
// resolve(blogs)
// })
// })
// }
// }

0 comments on commit 386e498

Please sign in to comment.