const std = @import("std"); const jetzig = @import("jetzig"); const RssItem = struct { id: i32, title: []const u8, blob: []const u8, content: []const u8, created_at: jetzig.jetquery.DateTime, updated_at: jetzig.jetquery.DateTime, }; fn generateRss(items: []const RssItem, allocator: std.mem.Allocator) ![]u8 { var list = std.ArrayList(u8).init(allocator); const writer = list.writer(); try writer.print( \\ \\ \\ \\yuzucchii.xyz \\yuzucchii.xyz \\Personal blog of Yuzu with all kinds of different articles , .{}); for (items) |item| { try writer.print( \\ \\{s} \\yuzucchii.xyz/blogs/{d} \\{s} , .{ item.title, item.id, item.blob }); try item.created_at.strftime(writer, "Day, DD Mon YYYY HH:MM:SS GMT"); try writer.print( \\ , .{}); } try writer.writeAll(""); return list.toOwnedSlice(); } // we'll send xml instead pub fn index(request: *jetzig.Request) !void { try request.headers.append("Content-Type", "application/rss+xml"); const query = jetzig.database.Query(.Blog).orderBy(.{.created_at = .desc}); const blogs = try request.repo.all(query); var items: std.ArrayList(RssItem) = .init(request.allocator); for (blogs) |blog| { try items.append(RssItem{ .id = blog.id, .title = blog.title, .blob = blog.blob, .content = blog.content orelse "", .created_at = blog.created_at, .updated_at = blog.updated_at, }); } // TODO: wait until jetzig adds xml support _ = try generateRss(try items.toOwnedSlice(), request.allocator); return request.render(.ok); }