The RSS is created using xs_html.

This commit is contained in:
default 2023-11-20 19:25:53 +01:00
parent 7dd1c8a1ba
commit a6a51903ef

77
html.c
View file

@ -2136,31 +2136,33 @@ int html_get_handler(const xs_dict *req, const char *q_path,
if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE) if (xs_type(xs_dict_get(snac.config, "private")) == XSTYPE_TRUE)
return 403; return 403;
xs_str *rss;
xs *elems = timeline_simple_list(&snac, "public", 0, 20); xs *elems = timeline_simple_list(&snac, "public", 0, 20);
xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL); xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"), NULL);
char *p, *v;
xs *es1 = xs_html_encode(xs_dict_get(snac.config, "name")); xs *rss_title = xs_fmt("%s (@%s@%s)",
xs *es2 = xs_html_encode(snac.uid); xs_dict_get(snac.config, "name"),
xs *es3 = xs_html_encode(xs_dict_get(srv_config, "host")); snac.uid,
xs *es4 = xs_html_encode(bio); xs_dict_get(srv_config, "host"));
rss = xs_fmt( xs *rss_link = xs_fmt("%s.rss", snac.actor);
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<rss version=\"0.91\">\n" xs_html *rss = xs_html_tag("rss",
"<channel>\n" xs_html_attr("version", "0.91"));
"<title>%s (@%s@%s)</title>\n"
"<language>en</language>\n" xs_html *channel = xs_html_tag("channel",
"<link>%s.rss</link>\n" xs_html_tag("title",
"<description>%s</description>\n", xs_html_text(rss_title)),
es1, xs_html_tag("language",
es2, xs_html_text("en")),
es3, xs_html_tag("link",
snac.actor, xs_html_text(rss_link)),
es4 xs_html_tag("description",
); xs_html_text(bio)));
xs_html_add(rss, channel);
xs_list *p = elems;
char *v;
p = elems;
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *msg = NULL; xs *msg = NULL;
@ -2168,38 +2170,31 @@ int html_get_handler(const xs_dict *req, const char *q_path,
continue; continue;
char *id = xs_dict_get(msg, "id"); char *id = xs_dict_get(msg, "id");
char *content = xs_dict_get(msg, "content");
if (!xs_startswith(id, snac.actor)) if (!xs_startswith(id, snac.actor))
continue; continue;
xs *content = xs_html_encode(xs_dict_get(msg, "content")); /* create a title with the first line of the content */
xs *es_title = xs_replace(content, "<br>", "\n");
// We SHOULD only use sanitized one for description.
// So, only encode for feed title, while the description just keep it sanitized as is.
xs *es_title_enc = encode_html(xs_dict_get(msg, "content"));
xs *es_title = xs_replace(es_title_enc, "<br>", "\n");
xs *title = xs_str_new(NULL); xs *title = xs_str_new(NULL);
int i; int i;
for (i = 0; es_title[i] && es_title[i] != '\n' && es_title[i] != '&' && i < 50; i++) for (i = 0; es_title[i] && es_title[i] != '\n' && es_title[i] != '&' && i < 50; i++)
title = xs_append_m(title, &es_title[i], 1); title = xs_append_m(title, &es_title[i], 1);
xs *s = xs_fmt( xs_html_add(channel,
"<item>\n" xs_html_tag("item",
"<title>%s...</title>\n" xs_html_tag("title",
"<link>%s</link>\n" xs_html_text(title)),
"<description>%s</description>\n" xs_html_tag("link",
"</item>\n", xs_html_text(id)),
title, id, content xs_html_tag("description",
); xs_html_text(content))));
rss = xs_str_cat(rss, s);
} }
rss = xs_str_cat(rss, "</channel>\n</rss>\n"); *body = _xs_html_render(rss, xs_dup("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"));
*b_size = strlen(*body);
*body = rss;
*b_size = strlen(rss);
*ctype = "application/rss+xml; charset=utf-8"; *ctype = "application/rss+xml; charset=utf-8";
status = 200; status = 200;