From: Alexander Goussas Date: Sun, 3 May 2026 21:11:43 +0000 (-0500) Subject: feat: format an empty RSS document X-Git-Url: http://git.frustrated-labs.net/?a=commitdiff_plain;h=234aadd6225ef818d5adf19f66d60ca6096012d4;p=frustrated-functor.dev.git feat: format an empty RSS document --- diff --git a/bin/blog-processor/src/root.zig b/bin/blog-processor/src/root.zig index 8634ea0..6a8db43 100644 --- a/bin/blog-processor/src/root.zig +++ b/bin/blog-processor/src/root.zig @@ -53,4 +53,5 @@ test "all tests" { _ = @import("./html_formatter.zig"); _ = @import("./string_utils.zig"); _ = @import("./rss_formatter.zig"); + _ = @import("./rss_document.zig"); } diff --git a/bin/blog-processor/src/rss_document.zig b/bin/blog-processor/src/rss_document.zig new file mode 100644 index 0000000..7b7cbe7 --- /dev/null +++ b/bin/blog-processor/src/rss_document.zig @@ -0,0 +1,60 @@ +const std = @import("std"); + +const rss = @import("./rss_formatter.zig"); +const md = @import("./markdown_parser.zig"); + +const HEADER = + \\ + \\ + \\ + \\Posts on Alexander Goussas + \\https://frustrated-functor.dev + \\ + \\ + \\en-us + \\goussasalexander@gmail.com (Alexander Goussas) + \\goussasalexander@gmail.com (Alexander Goussas) + \\ + \\ + ; + +const FOOTER = + \\ + \\ + ; + +// TODO: Create a MarkdownMetaDoc that includes the post URL. + +pub const RssDocument = struct { + buffer: std.ArrayList(u8) = .empty, + + pub fn md2rss(self: *@This(), alloc: std.mem.Allocator, docs: std.ArrayList(md.MarkdownDoc)) ![]const u8 { + try self.buffer.appendSlice(alloc, HEADER); + + for (docs.items) |doc| { + // TODO: Thread URL here. + // TODO: Add an API to RSS formatter to be able to reset the buffer. + var rssFormatter = rss.RssFormatter.init(alloc, ""); + defer rssFormatter.deinit(); + + const formattedEntry = try rssFormatter.format(doc); + try self.buffer.appendSlice(alloc, formattedEntry); + } + + try self.buffer.appendSlice(alloc, FOOTER); + + return self.buffer.toOwnedSlice(alloc); + } +}; + +test "rss document can format an empty document" { + const alloc = std.testing.allocator; + + var rssDoc: RssDocument = .{}; + + const docs: std.ArrayList(md.MarkdownDoc) = .empty; + const result = try rssDoc.md2rss(alloc, docs); + defer alloc.free(result); + + try std.testing.expectEqualStrings(HEADER ++ FOOTER, result); +}