commit d67436f

grunfink  ·  2026-03-19 18:15:22 +0000 UTC
parent c208611
Add attachments to RSS.
1 files changed,  +41, -1
M rss.c
M rss.c
+41, -1
 1@@ -101,6 +101,46 @@ xs_str *rss_from_timeline(snac *user, const xs_list *timeline,
 2                 xs_html_tag("lastBuildDate",
 3                     xs_html_text(rss_date)));
 4 
 5+        xs *att_content = xs_dup(content);
 6+        xs *attach_list = get_attachments(msg);
 7+
 8+        /* add possible attachments */
 9+        if (xs_list_len(attach_list)) {
10+            const xs_val *a;
11+            xs_html *content_attachments = xs_html_tag("div",
12+                xs_html_attr("class", "snac-content-attachments"));
13+
14+            xs_list_foreach(attach_list, a) {
15+                const char *type = xs_dict_get(a, "type");
16+                const char *o_href = xs_dict_get(a, "href");
17+                const char *name = xs_dict_get_def(a, "name", "");
18+
19+                if (!xs_is_string(type) || !xs_is_string(o_href))
20+                    continue;
21+
22+                if (xs_startswith(type, "image/")) {
23+                    xs_html_add(content_attachments,
24+                        xs_html_tag("figure",
25+                            xs_html_sctag("img",
26+                                xs_html_attr("src", o_href)),
27+                            xs_html_tag("figcaption",
28+                                xs_html_text(name))));
29+                }
30+                else {
31+                    xs_html_add(content_attachments,
32+                        xs_html_tag("a",
33+                            xs_html_attr("href", o_href),
34+                            xs_html_text(name),
35+                            xs_html_text(" "),
36+                            xs_html_text(o_href),
37+                        xs_html_sctag("br", NULL)));
38+                }
39+            }
40+
41+            xs *s1 = xs_html_render(content_attachments);
42+            att_content = xs_str_cat(att_content, s1);
43+        }
44+
45         xs_html_add(channel,
46             xs_html_tag("item",
47                 xs_html_tag("title",
48@@ -112,7 +152,7 @@ xs_str *rss_from_timeline(snac *user, const xs_list *timeline,
49                 xs_html_tag("pubDate",
50                     xs_html_text(rss_date)),
51                 xs_html_tag("description",
52-                    xs_html_text(content))));
53+                    xs_html_text(att_content))));
54 
55         cnt++;
56     }