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, ...valueParts] = line.split(':'); if (key && valueParts.length > 0) { metadata[key.trim()] = valueParts.join(':').trim(); } }); return ''; }); // Configure marked options for proper heading rendering const markedOptions = { headerIds: true, gfm: true, breaks: true, pedantic: false, smartLists: true, smartypants: true }; // Convert markdown to HTML const articleContent = marked.parse(content, markedOptions); // Calculate read time (rough estimate: 200 words per minute) const wordCount = content.trim().split(/\s+/).length; const readTime = Math.ceil(wordCount / 200); // Create full HTML document const html = ` ${metadata.title || 'Blog Post'} - Glenn Thompson
Back to Home

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

${readTime} min read By ${metadata.author || 'Glenn Thompson'}
${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); }