From: Alexander Goussas Date: Sun, 3 May 2026 20:42:08 +0000 (-0500) Subject: feat: add link and guid to generated rss entries X-Git-Url: http://git.frustrated-labs.net/?a=commitdiff_plain;h=1771d88333312591f5f743ee7ad95e5a5942e64f;p=frustrated-functor.dev.git feat: add link and guid to generated rss entries --- diff --git a/bin/blog-processor/src/rss_formatter.zig b/bin/blog-processor/src/rss_formatter.zig index a6fabfc..8ad27f7 100644 --- a/bin/blog-processor/src/rss_formatter.zig +++ b/bin/blog-processor/src/rss_formatter.zig @@ -5,12 +5,15 @@ const md = @import("./markdown_parser.zig"); pub const RssFormatter = struct { buffer: std.ArrayList(u8), alloc: std.mem.Allocator, + /// URL of the live post + url: []const u8, /// Create a new RssFormatter that will use the provided allocator. - pub fn init(alloc: std.mem.Allocator) @This() { + pub fn init(alloc: std.mem.Allocator, url: []const u8) @This() { return .{ .buffer = .empty, .alloc = alloc, + .url = url, }; } @@ -24,29 +27,27 @@ pub const RssFormatter = struct { self.alloc, \\ \\goussasalexander@gmail.com (Alexander Goussas) - \\ + \\ ); - try self.buffer.appendSlice(self.alloc, doc.date); - try self.buffer.appendSlice( - self.alloc, - \\ - \\ - ); + try self.tag("<pubDate>", "</pubDate>", doc.date); + try self.tag("<title>", "", doc.title); + try self.tag("", "", self.url); + try self.tag("", "", self.url); - try self.buffer.appendSlice(self.alloc, doc.title); - try self.buffer.appendSlice( - self.alloc, - \\ - \\ - ); - - // TODO: Add link - // TODO: Add guid (same as link) + try self.buffer.appendSlice(self.alloc, ""); + // TODO: Add a description return self.buffer.items; } + + fn tag(self: *@This(), openingTag: []const u8, closingTag: []const u8, inside: []const u8) !void { + try self.buffer.appendSlice(self.alloc, openingTag); + try self.buffer.appendSlice(self.alloc, inside); + try self.buffer.appendSlice(self.alloc, closingTag); + try self.buffer.append(self.alloc, '\n'); + } }; test "rss formatter can format markdown document" { @@ -60,7 +61,8 @@ test "rss formatter can format markdown document" { \\Aujourd'hui, mamam est morte. ; - var formatter = RssFormatter.init(alloc); + const postURL = "https://frustrated-functor.dev/a-post-title.md.html"; + var formatter = RssFormatter.init(alloc, postURL); defer formatter.deinit(); var mdDoc = try md.MarkdownDoc.parse(doc, alloc); @@ -73,6 +75,8 @@ test "rss formatter can format markdown document" { \\goussasalexander@gmail.com (Alexander Goussas) \\12 april 2026 \\A post title + \\https://frustrated-functor.dev/a-post-title.md.html + \\https://frustrated-functor.dev/a-post-title.md.html \\ , result