You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
import fh from 'filehound';
|
|
import fs from 'fs-extra';
|
|
import metadataParser from 'markdown-yaml-metadata-parser';
|
|
import _ from 'lodash';
|
|
|
|
export default class Pages {
|
|
//--------------------------
|
|
// constructor
|
|
//--------------------------
|
|
constructor() {}
|
|
//--------------------------
|
|
// methods
|
|
//--------------------------
|
|
start() {}
|
|
|
|
getPage(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 {
|
|
setTimeout(() => {
|
|
//TODO: Duct tape solution until something better created
|
|
let page = _.find(pages, list => {
|
|
return list.metadata.uuid === id;
|
|
});
|
|
resolve(page);
|
|
}, 100);
|
|
}
|
|
})
|
|
.catch(err => {
|
|
reject(err);
|
|
});
|
|
});
|
|
}
|
|
//--------------------------
|
|
// event handlers
|
|
//--------------------------
|
|
}
|