Forked from yoamomonstruos/gist:a43032a7216862cd494d
Last active
March 11, 2016 18:13
-
-
Save KATT/b1315016081915666a3e to your computer and use it in GitHub Desktop.
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
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