1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| var id = 0;
function readFileList(dir, filesList = []) { const files = fs.readdirSync(dir); files.forEach((item, index) => { var fullPath = path.join(dir, item); const stat = fs.statSync(fullPath); if (stat.isDirectory()) { readFileList(path.join(dir, item), filesList); } else { if (item.slice(-3).toLowerCase() == ".md") { fullPath = fullPath.replace(/\\/g, "/"); var path_sp = fullPath.split("/"); filesList.push({ id: id++, userId: 1, title: item.slice(0, -3), year: path_sp[path_sp.length - 3], month: path_sp[path_sp.length - 2], path: fullPath, body: fs.readFileSync(fullPath).toString(), }); } } }); return filesList; }
var blog_md_list = [];
readFileList(path.join(__dirname, "public", "md"), blog_md_list);
|