65 lines
1.4 KiB
JavaScript
65 lines
1.4 KiB
JavaScript
const showdown = require('showdown');
|
|
const showdownKatex = require('showdown-katex');
|
|
const fs = require('fs/promises');
|
|
const path = require('path');
|
|
|
|
const converter = new showdown.Converter({
|
|
extensions: [showdownKatex()],
|
|
});
|
|
|
|
if (process.argv.length < 3) {
|
|
process.exit(1);
|
|
}
|
|
|
|
async function readFile(filename) {
|
|
try {
|
|
const data = await fs.readFile(filename, { encoding: 'utf-8' });
|
|
return data;
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
|
|
console.log('fuck');
|
|
}
|
|
|
|
async function makeHtml() {
|
|
const markdown = await readFile(process.argv[2]);
|
|
const newFileName = path.parse(process.argv[2]).name + '.html';
|
|
const html = converter.makeHtml(markdown);
|
|
|
|
let contents = `
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Benjamin Bergstrom's blog</title>
|
|
<link rel="stylesheet" href="../../css/style.css">
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<p>
|
|
<a href="https://tilde.team/~benko11/blog">~ back to blog</a>
|
|
</p>
|
|
|
|
${html}
|
|
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`;
|
|
|
|
try {
|
|
await fs.writeFile(`articles/${newFileName}`, contents);
|
|
console.log(
|
|
`Open at https://tilde.team/~benko11/blog/articles/${newFileName}`
|
|
);
|
|
} catch (err) {
|
|
console.error(err);
|
|
return;
|
|
}
|
|
}
|
|
|
|
makeHtml();
|