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
5 years ago
|
import fh from 'filehound';
|
||
|
import fs from 'fs-extra';
|
||
|
import metadataParser from 'markdown-yaml-metadata-parser';
|
||
5 years ago
|
import _ from 'lodash';
|
||
5 years ago
|
|
||
|
export default class Pages {
|
||
|
//--------------------------
|
||
|
// constructor
|
||
|
//--------------------------
|
||
|
constructor() {}
|
||
|
//--------------------------
|
||
|
// methods
|
||
|
//--------------------------
|
||
|
start() {}
|
||
|
|
||
5 years ago
|
getPage(id) {
|
||
5 years ago
|
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));
|
||
|
});
|
||
|
}
|
||
5 years ago
|
|
||
5 years ago
|
if (id === null || id === null || id === undefined) {
|
||
|
setTimeout(() => {
|
||
|
//TODO: Duct tape solution until something better created
|
||
|
resolve(pages);
|
||
|
}, 100);
|
||
|
} else {
|
||
5 years ago
|
setTimeout(() => {
|
||
|
//TODO: Duct tape solution until something better created
|
||
|
let page = _.find(pages, list => {
|
||
|
return list.metadata.uuid === id;
|
||
|
});
|
||
|
resolve(page);
|
||
|
}, 100);
|
||
5 years ago
|
}
|
||
|
})
|
||
|
.catch(err => {
|
||
|
reject(err);
|
||
|
});
|
||
|
});
|
||
|
}
|
||
|
//--------------------------
|
||
|
// event handlers
|
||
|
//--------------------------
|
||
|
}
|