-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
// }) | ||
// }) | ||
// } | ||
// } |