const { marked } = require('marked'); const fs = require('fs'); const path = require('path'); // Configure marked options const options = { headerIds: true, gfm: true }; // Footer template const footer = ` `; function convertMarkdownToHtml(mdFilePath) { // Read markdown file const markdown = fs.readFileSync(mdFilePath, 'utf-8'); // Extract metadata from markdown (assuming front matter) const metadata = {}; const content = markdown.replace(/^---\n([\s\S]*?)\n---\n/, (_, frontMatter) => { frontMatter.split('\n').forEach(line => { const [key, value] = line.split(': '); if (key && value) { metadata[key.trim()] = value.trim(); } }); return ''; }); // Convert markdown to HTML const articleContent = marked.parse(content, options); // Create full HTML document const html = ` ${metadata.title || 'Blog Post'} - Glenn Thompson

${metadata.title || 'Blog Post'}

${metadata.category || 'Blog'}
${articleContent}
${footer}`; // Write HTML file const htmlFilePath = mdFilePath.replace(/\.md$/, '.html'); fs.writeFileSync(htmlFilePath, html); console.log(`Converted ${path.basename(mdFilePath)} to HTML`); } // If running from command line if (require.main === module) { const mdFilePath = process.argv[2]; if (!mdFilePath) { console.error('Please provide a markdown file path'); process.exit(1); } convertMarkdownToHtml(mdFilePath); }