Skip to content

Instantly share code, notes, and snippets.

@KATT
Forked from yoamomonstruos/gist:a43032a7216862cd494d
Last active March 11, 2016 18:13
Show Gist options
  • Save KATT/b1315016081915666a3e to your computer and use it in GitHub Desktop.
Save KATT/b1315016081915666a3e to your computer and use it in GitHub Desktop.
function getFrontMatter(file) {
return new Promise((resolve, reject) => {
readFile(join(__dirname, '../pages', file), (error, content) => {
if (error) return reject(error);
let doc = fm(content.toString())
resolve(doc);
});
})
}
async function getAllPages() {
return new Promise((resolve, reject) => {
glob('**/*.md', { cwd: join(__dirname, '../pages') }, (err, files) => {
if (err) return reject(err);
const result = files.map(file => {
let path = '/' + file.substr(0, file.lastIndexOf('.'));
if (path === '/index') {
path = '/';
} else if (path.endsWith('/index')) {
path = path.substr(0, path.lastIndexOf('/index'));
}
let data = await getFrontMatter(file);
return { path, file, data }
});
resolve(result);
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment