import fs from 'fs'; import marked from 'marked'; import highlight from 'highlight.js'; marked.setOptions({ header: true, highlight: (code) => { return highlight.highlightAuto(code).value; } }); const dir = './posts/'; const json = { posts: [] }; //do everything synchronously to keep posts ordered function parse_dir(dir, folder_name){ const posts = fs.readdirSync(dir); for(let post of posts){ const stats = fs.statSync(dir + post); if(stats.isDirectory()){ parse_dir(dir + post + '/', post); } else { const file = fs.readFileSync(dir+post, 'utf8'); const tokens = marked.lexer(file, null); const path = dir + post; const temp = { path: path.slice(1, path.length), category: folder_name, date: post.slice(0, 10), title: marked('