size: 1 KiB

1const std = @import("std");
2const Io = std.Io;
3
4const Post = @import("Post.zig");
5const Meta = @import("Meta.zig");
6const html = @import("html.zig");
7
8pub const feed_path = "atom.xml";
9
10pub fn atom(args: struct {
11 arena: std.mem.Allocator,
12 writer: *Io.Writer,
13 meta: Meta,
14 posts: []Post,
15 now: []const u8,
16}) !void {
17 const w = args.writer;
18 const arena = args.arena;
19
20 try w.writeAll(
21 \\<?xml version="1.0" encoding="utf-8"?>
22 \\<feed xmlns="http://www.w3.org/2005/Atom">
23 \\
24 );
25
26 try html.tag(w, "title", args.meta.site_name);
27 try html.tag(w, "subtitle", args.meta.tagline);
28 try w.print(
29 \\<link href="{0s}/{1s}" rel="self" />
30 \\<id>{0s}/</id>
31 \\<updated>{2s}</updated>
32 \\
33 , .{
34 args.meta.domain,
35 feed_path,
36 args.now,
37 });
38
39 for (args.posts) |p| {
40 try w.print(
41 \\<entry>
42 \\ <id>{s}/{s}/</id>
43 \\ <title>{s}</title>
44 \\ <updated>{s}</updated>
45 \\</entry>
46 \\
47 , .{
48 args.meta.domain,
49 try html.escapeAlloc(arena, p.slug),
50 try html.escapeAlloc(arena, p.title),
51 try html.escapeAlloc(arena, p.published_at),
52 });
53 }
54
55 try w.writeAll(
56 \\</feed>
57 \\
58 );
59}