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/processPosts.js | 121 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 _posts/processPosts.js (limited to '_posts/processPosts.js') 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