fipamo/brain/data/Pages.js
2019-11-23 00:13:53 -08:00

46 lines
1 KiB
JavaScript

import fh from 'filehound';
import fs from 'fs-extra';
import metadataParser from 'markdown-yaml-metadata-parser';
export default class Pages {
//--------------------------
// constructor
//--------------------------
constructor() {}
//--------------------------
// methods
//--------------------------
start() {}
grab(id) {
return new Promise((resolve, reject) => {
fh.create()
.paths('content/pages')
.ext('md')
.find()
.then(files => {
let pages = [];
for (let index = 0; index < files.length; index++) {
fs.readFile(files[index], { encoding: 'utf8' }, (err, file) => {
pages.push(metadataParser(file));
});
}
if (id === null || id === null || id === undefined) {
setTimeout(() => {
//TODO: Duct tape solution until something better created
resolve(pages);
}, 100);
} else {
// find specific pages
}
})
.catch(err => {
reject(err);
});
});
}
//--------------------------
// event handlers
//--------------------------
}