RSS improvements.

This commit is contained in:
default 2022-11-19 06:15:35 +01:00
parent 3598e61d74
commit 50d73a6e94

28
html.c
View File

@ -1098,19 +1098,26 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
/* public timeline in RSS format */ /* public timeline in RSS format */
d_char *rss; d_char *rss;
xs *elems = local_list(&snac, 20); xs *elems = local_list(&snac, 20);
xs *bio = not_really_markdown(xs_dict_get(snac.config, "bio"));
char *p, *v; char *p, *v;
/* escape tags */
bio = xs_replace_i(bio, "<", "&lt;");
bio = xs_replace_i(bio, ">", "&gt;");
rss = xs_fmt( rss = xs_fmt(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<rss version=\"0.91\">\n" "<rss version=\"0.91\">\n"
"<channel>\n" "<channel>\n"
"<title>%s</title>\n" "<title>%s (@%s@%s)</title>\n"
"<language>en</language>\n" "<language>en</language>\n"
"<link>%s.rss</link>\n" "<link>%s.rss</link>\n"
"<description>%s</description>\n", "<description>%s</description>\n",
xs_dict_get(snac.config, "name"),
snac.uid,
xs_dict_get(srv_config, "host"),
snac.actor, snac.actor,
snac.actor, bio
snac.actor
); );
p = elems; p = elems;
@ -1122,30 +1129,19 @@ int html_get_handler(d_char *req, char *q_path, char **body, int *b_size, char *
continue; continue;
xs *content = sanitize(xs_dict_get(msg, "content")); xs *content = sanitize(xs_dict_get(msg, "content"));
xs *title = xs_dup(content); char *title = xs_dict_get(msg, "published");
/* escape tags */ /* escape tags */
content = xs_replace_i(content, "<", "&lt;"); content = xs_replace_i(content, "<", "&lt;");
content = xs_replace_i(content, ">", "&gt;"); content = xs_replace_i(content, ">", "&gt;");
/* cut title in the first tag start */
if ((v = strchr(title, '<')))
*v = '\0';
if ((v = strchr(title, '&')))
*v = '\0';
if (strlen(title) > 40) {
title = xs_crop(title, 0, 40);
title = xs_str_cat(title, "...");
}
xs *s = xs_fmt( xs *s = xs_fmt(
"<item>\n" "<item>\n"
"<title>%s</title>\n" "<title>%s</title>\n"
"<link>%s</link>\n" "<link>%s</link>\n"
"<description>%s</description>\n" "<description>%s</description>\n"
"</item>\n", "</item>\n",
*title ? title : "...", id, content xs_is_null(title) ? "..." : title, id, content
); );
rss = xs_str_cat(rss, s); rss = xs_str_cat(rss, s);