summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar default2023-11-20 19:25:53 +0100
committerGravatar default2023-11-20 19:25:53 +0100
commita6a51903ef13b6ac6dc7fd1976eef07be2bf4562 (patch)
treecffe2bbd6fd65a0ecf712ff1cd8b7cdaf2c73970
parentUse xs_html in html_footer(). (diff)
downloadsnac2-a6a51903ef13b6ac6dc7fd1976eef07be2bf4562.tar.gz
snac2-a6a51903ef13b6ac6dc7fd1976eef07be2bf4562.tar.xz
snac2-a6a51903ef13b6ac6dc7fd1976eef07be2bf4562.zip
The RSS is created using xs_html.
-rw-r--r--html.c77
1 files changed, 36 insertions, 41 deletions
diff --git a/html.c b/html.c
index 3472cd4..61d2f10 100644
--- a/html.c
+++ b/html.c
@@ -2136,31 +2136,33 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2136 if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE) 2136 if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
2137 return 403; 2137 return 403;
2138 2138
2139 xs_str *rss;
2140 xs *elems = timeline_simple_list(&snac, "public", 0, 20); 2139 xs *elems = timeline_simple_list(&snac, "public", 0, 20);
2141 xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); 2140 xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
2142 char *p, *v;
2143 2141
2144 xs *es1 = xs_html_encode(xs_dict_get(snac.config, "name")); 2142 xs *rss_title = xs_fmt("%s (@%s@%s)",
2145 xs *es2 = xs_html_encode(snac.uid); 2143 xs_dict_get(snac.config, "name"),
2146 xs *es3 = xs_html_encode(xs_dict_get(srv_config, "host")); 2144 snac.uid,
2147 xs *es4 = xs_html_encode(bio); 2145 xs_dict_get(srv_config, "host"));
2148 rss = xs_fmt( 2146 xs *rss_link = xs_fmt("%s.rss", snac.actor);
2149 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" 2147
2150 "<rss version=\"0.91\">\n" 2148 xs_html *rss = xs_html_tag("rss",
2151 "<channel>\n" 2149 xs_html_attr("version", "0.91"));
2152 "<title>%s (@%s@%s)</title>\n" 2150
2153 "<language>en</language>\n" 2151 xs_html *channel = xs_html_tag("channel",
2154 "<link>%s.rss</link>\n" 2152 xs_html_tag("title",
2155 "<description>%s</description>\n", 2153 xs_html_text(rss_title)),
2156 es1, 2154 xs_html_tag("language",
2157 es2, 2155 xs_html_text("en")),
2158 es3, 2156 xs_html_tag("link",
2159 snac.actor, 2157 xs_html_text(rss_link)),
2160 es4 2158 xs_html_tag("description",
2161 ); 2159 xs_html_text(bio)));
2160
2161 xs_html_add(rss, channel);
2162
2163 xs_list *p = elems;
2164 char *v;
2162 2165
2163 p = elems;
2164 while (xs_list_iter(&p, &v)) { 2166 while (xs_list_iter(&p, &v)) {
2165 xs *msg = NULL; 2167 xs *msg = NULL;
2166 2168
@@ -2168,38 +2170,31 @@ int html_get_handler(const xs_dict *req, const char *q_path,
2168 continue; 2170 continue;
2169 2171
2170 char *id = xs_dict_get(msg, "id"); 2172 char *id = xs_dict_get(msg, "id");
2173 char *content = xs_dict_get(msg, "content");
2171 2174
2172 if (!xs_startswith(id, snac.actor)) 2175 if (!xs_startswith(id, snac.actor))
2173 continue; 2176 continue;
2174 2177
2175 xs *content = xs_html_encode(xs_dict_get(msg, "content")); 2178 /* create a title with the first line of the content */
2176 2179 xs *es_title = xs_replace(content, "<br>", "\n");
2177 // We SHOULD only use sanitized one for description.
2178 // So, only encode for feed title, while the description just keep it sanitized as is.
2179 xs *es_title_enc = encode_html(xs_dict_get(msg, "content"));
2180 xs *es_title = xs_replace(es_title_enc, "<br>", "\n");
2181 xs *title = xs_str_new(NULL); 2180 xs *title = xs_str_new(NULL);
2182 int i; 2181 int i;
2183 2182
2184 for (i = 0; es_title[i] && es_title[i] != '\n' && es_title[i] != '&' && i < 50; i++) 2183 for (i = 0; es_title[i] && es_title[i] != '\n' && es_title[i] != '&' && i < 50; i++)
2185 title = xs_append_m(title, &es_title[i], 1); 2184 title = xs_append_m(title, &es_title[i], 1);
2186 2185
2187 xs *s = xs_fmt( 2186 xs_html_add(channel,
2188 "<item>\n" 2187 xs_html_tag("item",
2189 "<title>%s...</title>\n" 2188 xs_html_tag("title",
2190 "<link>%s</link>\n" 2189 xs_html_text(title)),
2191 "<description>%s</description>\n" 2190 xs_html_tag("link",
2192 "</item>\n", 2191 xs_html_text(id)),
2193 title, id, content 2192 xs_html_tag("description",
2194 ); 2193 xs_html_text(content))));
2195
2196 rss = xs_str_cat(rss, s);
2197 } 2194 }
2198 2195
2199 rss = xs_str_cat(rss, "</channel>\n</rss>\n"); 2196 *body = _xs_html_render(rss, xs_dup("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"));
2200 2197 *b_size = strlen(*body);
2201 *body = rss;
2202 *b_size = strlen(rss);
2203 *ctype = "application/rss+xml; charset=utf-8"; 2198 *ctype = "application/rss+xml; charset=utf-8";
2204 status = 200; 2199 status = 200;
2205 2200