diff options
author | Matthew Kosarek <matt.kosarek@canonical.com> | 2024-05-01 14:12:17 -0400 |
---|---|---|
committer | Matthew Kosarek <matt.kosarek@canonical.com> | 2024-05-01 14:12:17 -0400 |
commit | ece0f56d29509685f9b61642056f15f84a8a0726 (patch) | |
tree | 3882ad898a80ec498f406ce99cacf12cc94658b6 /_posts/processPosts.js | |
parent | 9262b5c798e1921c759addb492b592f3ccf64980 (diff) |
cleanup: quick update, removing outdated items
Diffstat (limited to '_posts/processPosts.js')
-rw-r--r-- | _posts/processPosts.js | 144 |
1 files changed, 0 insertions, 144 deletions
diff --git a/_posts/processPosts.js b/_posts/processPosts.js deleted file mode 100644 index 2bd6ff1..0000000 --- a/_posts/processPosts.js +++ /dev/null @@ -1,144 +0,0 @@ - - -const fs = require('fs'); -const path = require('path'); -const posts = require('./postList'); - -const tags = [ - { - id: 'personal', - title: 'Personal 👨' - }, - { - id: 'programming', - title: 'Programming 💻' - }, - { - id: 'books', - title: 'Books 📖' - }, - { - id: 'food', - title: 'Food 🍲' - } -] - -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 ` - <a href="${createTagFile(tag)}"><button id="${tag.id}">${tag.title}</button></a> - `; -} - -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,` -<!DOCTYPE html> -<html lang="en"> - <head> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <meta charset="utf-8"> - <link rel="stylesheet" href="/index.css"> - <link rel="stylesheet" href="/posts.css"> - <title>Matthew Kosarek</title> - <link rel="shortcut icon" href="/favicon/favicon.ico" type="image/x-icon"> - </head> - <body> - <header> - <h1>Matthew Kosarek</h1> - <nav> - <ul> - <li><a href='/'>🏡 Home</a></li> - <li><a href='/resume.html'>📘 CV</a></li> - <li><a href="https://www.linkedin.com/in/matthew-kosarek/">🏢 LinkedIn</a></li> - <li><a href='/posts.html'>📝 Posts</a></li> - </ul> - </nav> - </header> - - <article> - <h2>${post.title}</h2> - <h3>Created ${stats.birthtime.toLocaleString()}. Last updated: ${stats.mtime.toLocaleString()}</h3> - ${content} - </article> - </body> -</html> - `) - return '/posts/' + fileName; -} - -function createPostLink(post) { - return ` - <li><a href="${createPostServableFile(post)}">${post.title}</a></li> - `; -} - -function createPostPage(outputFile, postFilter) { - const output = ` -<!DOCTYPE html> -<html lang="en"> - <head> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <meta charset="utf-8"> - <link rel="stylesheet" href="/index.css"> - <link rel="stylesheet" href="/posts.css"> - <title>Matthew Kosarek</title> - <link rel="shortcut icon" href="/favicon/favicon.ico" type="image/x-icon"> - </head> - <body> - <header> - <h1>Matthew Kosarek</h1> - <nav> - <ul> - <li><a href='/'>🏡 Home</a></li> - <li><a href='/resume.html'>📘 CV</a></li> - <li><a href="https://www.linkedin.com/in/matthew-kosarek/">🏢 LinkedIn</a></li> - <li><a href='/posts.html'>📝 Posts</a></li> - </ul> - </nav> - </header> - - ${postFilter ? '' : `<section> - <h2>Tags</h2> - - <div id='tag_list'> - ${tags.map(createTag).join('\n')} - </div> - </section`} - - <section> - <h2>Posts</h2> - <ul id='post_list'> - ${posts.filter(post => !postFilter || post.tags.includes(postFilter)).map(createPostLink).join('')} - </ul> - </section> - </body> -</html> -` - - fs.writeFileSync(outputFile, output); -} - -createPostPage(path.join(__dirname, '..', 'posts.html')); |