Created
September 25, 2021 04:28
-
-
Save kubosho/3424aee65aa23b94f9592c0a7531e838 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
const path = require('path'); | |
const { mkdir, readFile, writeFile } = require('fs/promises'); | |
const { promisify } = require('util'); | |
const markdown = require('markdown-wasm'); | |
const glob = require('glob'); | |
const asyncGlob = promisify(glob); | |
const SRC_DIR = './src'; | |
const DIST_DIR = './build'; | |
const SOURCE = `${SRC_DIR}/texts/**/*.md`; | |
async function main() { | |
const markdownFileNameList = await asyncGlob(SOURCE); | |
markdownFileNameList.forEach(async (filename) => { | |
const distFilePath = filename.replace(SRC_DIR, DIST_DIR).replace('.md', '.html'); | |
const distDirName = path.dirname(distFilePath); | |
const contents = await readFile(filename, { encoding: 'utf-8' }); | |
const htmlString = markdown.parse(contents); | |
try { | |
await mkdir(distDirName, { recursive: true }); | |
} catch (err) { | |
console.error(err); | |
} | |
await writeFile(distFilePath, htmlString); | |
}); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment