/* This script runs through each markdown post and scrapes out the title and intro. folder/files within posts are scanned recursively each post is contained within category, which is supplied by the direct parent folder Posts are sorted by date Stores all metadata in ./public/metadata.json Client uses metadata to display posts on preview page */ import fs from 'fs'; import ncp from 'ncp'; import marked from 'marked'; import highlight from 'highlight.js'; const debug = process.env.NODE_ENV !== 'production'; marked.setOptions({ header: true, highlight: (code) => { return highlight.highlightAuto(code).value; } }); const rootDirectory = './posts/'; const json = { posts: [] }; //do everything synchronously to keep posts ordered //we are not worried about execution time since this script only runs once when building //ignores files that are not in a directory function parse_dir(dir, folder_name = null){ 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 if(folder_name !== null && folder_name !== 'images' && dir !== './posts/extras/'){ const file = fs.readFileSync(dir+post, 'utf8'); const tokens = marked.lexer(file, null); const temp = { filename: post.slice(0, post.length - 3), category: folder_name, date: post.slice(0, 10), title: `