const fs = require('fs'); const path = require('path'); const matter = require('gray-matter'); const postsDir = path.join(__dirname, '_posts'); const outputDir = path.join(__dirname, 'blog'); // Ensure output directory exists if (!fs.existsSync(outputDir)) { fs.mkdirSync(outputDir, { recursive: true }); } // Get all markdown files const files = fs.readdirSync(postsDir).filter(f => f.endsWith('.md')); // Parse and generate HTML for each post const posts = files.map(file => { const content = fs.readFileSync(path.join(postsDir, file), 'utf-8'); const { data: frontmatter, content: markdown } = matter(content); // Simple markdown to HTML conversion let html = markdown // Headers .replace(/^### (.*$)/gim, '
$2')
// Inline code
.replace(/`(.*?)`/g, '$1')
// Links
.replace(/\[(.*?)\]\((.*?)\)/g, '$1')
// Images
.replace(/!\[(.*?)\]\((.*?)\)/g, '') // Lists .replace(/^\- (.*$)/gim, '
${html}
`; // Clean up empty paragraphs html = html.replace(/<\/p>/g, ''); const slug = file.replace('.md', ''); const url = `/blog/${slug}/`; return { ...frontmatter, slug, url, html, date: frontmatter.date ? frontmatter.date.toISOString().split('T')[0] : '' }; }); // Sort posts by date (newest first) posts.sort((a, b) => new Date(b.date) - new Date(a.date)); const relativePath = process.env.GIT_URL ? '' : '../'; // Generate index page const indexHtml = `
Updates, tutorials, and thoughts on AI-powered journaling.
${post.excerpt}
` : ''}