From: Alexander Goussas Date: Sun, 19 Apr 2026 03:45:17 +0000 (-0500) Subject: finish beta pipeline for processing blog posts X-Git-Tag: v0.0.1~6 X-Git-Url: http://git.frustrated-labs.net/?a=commitdiff_plain;h=5247c708f57342880873cb1fb9441666f3affa6e;p=frustrated-functor.dev.git finish beta pipeline for processing blog posts --- diff --git a/README.md b/README.md index 7515ba5..58352cc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ +# frustrated-functor.dev +My personal blog. +I write my entries in markdown files that I convert into HTML with a Zig program I built. + +The public assets are then deployed in a Dockerfile for ease and portability. ## Notes diff --git a/bin/blog-processor/src/html_formatter.zig b/bin/blog-processor/src/html_formatter.zig index 99644ba..95d6be3 100644 --- a/bin/blog-processor/src/html_formatter.zig +++ b/bin/blog-processor/src/html_formatter.zig @@ -6,11 +6,11 @@ const stdC = @cImport({ @cInclude("stdio.h"); }); -const Options = struct { +pub const Options = struct { template: ?[]const u8, }; -const HtmlFormatter = struct { +pub const HtmlFormatter = struct { buffer: std.ArrayList(u8), opts: Options, diff --git a/bin/blog-processor/src/main.zig b/bin/blog-processor/src/main.zig index a624fad..d9bb7b2 100644 --- a/bin/blog-processor/src/main.zig +++ b/bin/blog-processor/src/main.zig @@ -1,8 +1,14 @@ const std = @import("std"); const blog_processor = @import("blog_processor"); -pub fn main() !void { - const alloc = std.heap.page_allocator; - const arena = std.heap.ArenaAllocator.init(alloc); - _ = arena; +pub fn main(init: std.process.Init) !void { + var dirName: []const u8 = undefined; + var args_iter = std.process.Args.iterate(init.minimal.args); + _ = args_iter.next(); // Skip exec name + while (args_iter.next()) |arg| { + dirName = arg; + break; + } + + try blog_processor.processBlog(init.arena.allocator(), init.io, dirName); } diff --git a/bin/blog-processor/src/root.zig b/bin/blog-processor/src/root.zig index 49eabb0..6978da5 100644 --- a/bin/blog-processor/src/root.zig +++ b/bin/blog-processor/src/root.zig @@ -1,7 +1,50 @@ -// const std = @import("std"); +const std = @import("std"); -// const md_parser = @import("./markdown_parser.zig"); -// const html = @import("./html_formatter.zig"); +const md_parser = @import("./markdown_parser.zig"); +const html = @import("./html_formatter.zig"); + +pub fn processBlog(alloc: std.mem.Allocator, io: std.Io, dirName: []const u8) !void { + const dir = try std.Io.Dir.openDirAbsolute(io, dirName, .{ .iterate = true}); + defer dir.close(io); + + var iter = dir.iterate(); + while(try iter.next(io)) |entry| { + try processFile(alloc, dir, io, entry.name); + } +} + +fn processFile(alloc: std.mem.Allocator, dir: std.Io.Dir, io: std.Io, fileName: []const u8) !void { + if (!std.mem.eql(u8, ".md", std.fs.path.extension(fileName))) return; + + const postContents = try std.Io.Dir.readFileAlloc(dir, io, fileName, alloc, .unlimited); + + var mdDoc = try md_parser.MarkdownDoc.parse(postContents, alloc); + defer mdDoc.deinit(alloc); + + // TODO: Customize this via command line + const templateFile = "templates/index.html"; + const template = try std.Io.Dir.readFileAlloc( + std.Io.Dir.cwd(), io, templateFile, alloc, .unlimited); + var formatter = html.HtmlFormatter.init(.{ .template = template }); + defer formatter.deinit(alloc); + + const htmlOut = try formatter.format(alloc, mdDoc); + + // TODO: Change to file stem + const baseName = std.fs.path.basename(fileName); + const ext = ".html"; + const newFileName = try alloc.alloc(u8, baseName.len + ext.len); + defer alloc.free(newFileName); + + @memcpy(newFileName.ptr, baseName); + @memcpy(newFileName[baseName.len..].ptr, ext); + + // TODO: Put them in public directory + try std.Io.Dir.cwd().writeFile(io, .{ + .data = htmlOut, + .sub_path = newFileName, + }); +} test "all tests" { _ = @import("./markdown_parser.zig"); diff --git a/index.html b/index.html deleted file mode 100644 index 9130eec..0000000 --- a/index.html +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - Alexander Goussas | Programming - - - - - - - - -

Alexander Goussas

-

Blog about programming and friends

- -
- -
- - - - diff --git a/posts/06-05-2026-language-checkpoint-april.md b/posts/06-05-2026-language-checkpoint-april.md index 1796338..f52fe66 100644 --- a/posts/06-05-2026-language-checkpoint-april.md +++ b/posts/06-05-2026-language-checkpoint-april.md @@ -1,7 +1,6 @@ --- -title: Language Checkpoint - April -tags: language-learning -date: 6 April 2026 +title: Language Checkpoint April +summary: shit --- This is my April 2026 language checkpoint. diff --git a/public/index.html b/public/index.html new file mode 100644 index 0000000..9130eec --- /dev/null +++ b/public/index.html @@ -0,0 +1,26 @@ + + + + + + Alexander Goussas | Programming + + + + + + + + +

Alexander Goussas

+

Blog about programming and friends

+ +
+ +
+ + + + diff --git a/public/styles.css b/public/styles.css new file mode 100644 index 0000000..ec02c07 --- /dev/null +++ b/public/styles.css @@ -0,0 +1,14 @@ +body { + width: 60%; + margin: auto; + margin-top: 1rem; + margin-bottom: 1rem; +} + +h1, h2 { + text-align: center; +} + +a { + text-decoration: underline; +} diff --git a/styles.css b/styles.css deleted file mode 100644 index ec02c07..0000000 --- a/styles.css +++ /dev/null @@ -1,14 +0,0 @@ -body { - width: 60%; - margin: auto; - margin-top: 1rem; - margin-bottom: 1rem; -} - -h1, h2 { - text-align: center; -} - -a { - text-decoration: underline; -} diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..22e7489 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,13 @@ + + + + Alexander Goussas + + + + +
+ {body} +
+ +