summaryrefslogtreecommitdiff
path: root/_posts
diff options
context:
space:
mode:
authormattkae <mattkae@protonmail.com>2022-11-13 19:51:56 -0500
committermattkae <mattkae@protonmail.com>2022-11-13 19:51:56 -0500
commitf75dfb5d736b644ad2649452c3056ba71be856b8 (patch)
tree903efbd21aa3872ec695394ae98a33e35ae79d3e /_posts
parenta17411cbb8e8a67ff9c4815bd96cdd4ddb1a1ddb (diff)
The dumbest of blogging systems
Diffstat (limited to '_posts')
-rw-r--r--_posts/hello_world.html9
-rw-r--r--_posts/processPosts.js121
2 files changed, 130 insertions, 0 deletions
diff --git a/_posts/hello_world.html b/_posts/hello_world.html
new file mode 100644
index 0000000..038f5db
--- /dev/null
+++ b/_posts/hello_world.html
@@ -0,0 +1,9 @@
+<p>
+ Hello, world!
+</p>
+<p>
+ This is the first test of my simple, static blogging system. My goal is to avoid using anything too heavy and, instead, provide a simple script that will get run whenever I update a blog post. Heck, I could even set it up to a cronjob to refresh them everyday. But perhaps that is overkill for today 😆. I am satisfied with how it current works.
+</p>
+<p>
+ Expect to see some updates on Greek philosophy, emacs, and Linux coming soon to a website near you!
+</p>
diff --git a/_posts/processPosts.js b/_posts/processPosts.js
new file mode 100644
index 0000000..9db4103
--- /dev/null
+++ b/_posts/processPosts.js
@@ -0,0 +1,121 @@
+
+
+const fs = require('fs');
+const path = require('path');
+
+const tags = [
+ {
+ id: 'personal',
+ title: 'Personal 👨'
+ }
+]
+
+const posts = [
+ {
+ url: "_posts/hello_world.html",
+ title: "Hello, World!",
+ tags: [ "personal" ]
+ }
+];
+
+function createTag(tag) {
+ return `
+ <button id="${tag.id}">${tag.title}</button>
+ `;
+}
+
+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('/'));
+ 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='/'>&#127969; Home</a></li>
+ <li><a href='/resume.html'>&#128216; CV</a></li>
+ <li><a href="https://www.linkedin.com/in/matthew-kosarek/">🏢 LinkedIn</a></li>
+ <li><a href='/posts.html'>&#128221; 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>
+ `;
+}
+
+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='/'>&#127969; Home</a></li>
+ <li><a href='/resume.html'>&#128216; CV</a></li>
+ <li><a href="https://www.linkedin.com/in/matthew-kosarek/">🏢 LinkedIn</a></li>
+ <li><a href='/posts.html'>&#128221; Posts</a></li>
+ </ul>
+ </nav>
+ </header>
+
+ <section>
+ <h2>Tags</h2>
+ <div id='tag_list'>
+ ${tags.map(createTag)}
+ </div>
+ </section
+
+ <section>
+ <h2>Posts</h2>
+ <ul id='post_list'>
+ ${posts.map(createPostLink)}
+ </ul>
+ </section>
+ </body>
+</html>
+`
+
+fs.writeFileSync(path.join(__dirname, '..', 'posts.html'), output);