From f75dfb5d736b644ad2649452c3056ba71be856b8 Mon Sep 17 00:00:00 2001 From: mattkae Date: Sun, 13 Nov 2022 19:51:56 -0500 Subject: The dumbest of blogging systems --- _posts/hello_world.html | 9 ++++ _posts/processPosts.js | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 _posts/hello_world.html create mode 100644 _posts/processPosts.js (limited to '_posts') 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 @@ +

+ Hello, world! +

+

+ 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. +

+

+ Expect to see some updates on Greek philosophy, emacs, and Linux coming soon to a website near you! +

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 ` + + `; +} + +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,` + + + + + + + + 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}
  • + `; +} + +const output = ` + + + + + + + + Matthew Kosarek + + + +
    +

    Matthew Kosarek

    + +
    + +
    +

    Tags

    +
    + ${tags.map(createTag)} +
    +
    +

    Posts

    + + + + +` + +fs.writeFileSync(path.join(__dirname, '..', 'posts.html'), output); -- cgit v1.2.1