const fs = require('fs'); const path = require('path'); const tags = [ { id: 'personal', title: 'Personal 👨' }, { id: 'programming', title: 'Programming 💻' }, { id: 'books', title: 'Books 📖' }, { id: 'food', title: 'Food 🍲' } ] const posts = [ { url: "_posts/hello_world.html", title: "Hello, World!", tags: [ "personal" ] }, { url: "_posts/plato_1.html", title: "Euthyphro: the pious and the god-loved", tags: [ "books" ] } ]; function createTagFile(tag) { const dir = path.resolve(path.join(__dirname, '..', 'posts')); if (!fs.existsSync(dir)) { fs.mkdirSync(dir); } const tagFileName = `tag_${tag.id}.html` createPostPage(path.join(__dirname, '..', 'posts', tagFileName), tag.id) return `/posts/${tagFileName}`; } function createTag(tag) { return ` `; } function createPostServableFile(post) { const dir = path.resolve(path.join(__dirname, '..', 'posts')); if (!fs.existsSync(dir)) { fs.mkdirSync(dir); } const baseFilePath = path.join(__dirname, '..', post.url); const stats = fs.statSync(baseFilePath); const content = fs.readFileSync(baseFilePath); const fileName = post.url.substring(post.url.lastIndexOf('/') + 1); const filePath = path.join(dir, fileName); fs.writeFileSync(filePath,` Matthew Kosarek

Matthew Kosarek

${post.title}

Created ${stats.birthtime.toLocaleString()}. Last updated: ${stats.mtime.toLocaleString()}

${content}
`) return '/posts/' + fileName; } function createPostLink(post) { return `
  • ${post.title}
  • `; } function createPostPage(outputFile, postFilter) { const output = ` Matthew Kosarek

    Matthew Kosarek

    ${postFilter ? '' : `

    Tags

    ${tags.map(createTag).join('\n')}

    Posts

    ` fs.writeFileSync(outputFile, output); } createPostPage(path.join(__dirname, '..', 'posts.html'));