Skip to content

Instantly share code, notes, and snippets.

@kubosho
Created September 25, 2021 04:28
Show Gist options
  • Save kubosho/3424aee65aa23b94f9592c0a7531e838 to your computer and use it in GitHub Desktop.
Save kubosho/3424aee65aa23b94f9592c0a7531e838 to your computer and use it in GitHub Desktop.
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