mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-21 21:05:05 +00:00
RSS feeds are now 2.0 instead of 0.91.
This commit is contained in:
parent
5e37c780da
commit
d9b94a556a
2 changed files with 35 additions and 5 deletions
37
html.c
37
html.c
|
@ -3839,11 +3839,14 @@ int html_post_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
|
||||
|
||||
xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc)
|
||||
xs_str *timeline_to_rss(snac *user, const xs_list *timeline,
|
||||
const char *title, const char *link, const char *desc)
|
||||
/* converts a timeline to rss */
|
||||
{
|
||||
xs_html *rss = xs_html_tag("rss",
|
||||
xs_html_attr("version", "0.91"));
|
||||
xs_html_attr("xmlns:content", "http:/" "/purl.org/rss/1.0/modules/content/"),
|
||||
xs_html_attr("version", "2.0"),
|
||||
xs_html_attr("xmlns:atom", "http:/" "/www.w3.org/2005/Atom"));
|
||||
|
||||
xs_html *channel = xs_html_tag("channel",
|
||||
xs_html_tag("title",
|
||||
|
@ -3852,15 +3855,21 @@ xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *
|
|||
xs_html_text("en")),
|
||||
xs_html_tag("link",
|
||||
xs_html_text(link)),
|
||||
xs_html_sctag("atom:link",
|
||||
xs_html_attr("href", link),
|
||||
xs_html_attr("rel", "self"),
|
||||
xs_html_attr("type", "application/rss+xml")),
|
||||
xs_html_tag("generator",
|
||||
xs_html_text(USER_AGENT)),
|
||||
xs_html_tag("description",
|
||||
xs_html_text(desc)));
|
||||
|
||||
xs_html_add(rss, channel);
|
||||
|
||||
int c = 0;
|
||||
int cnt = 0;
|
||||
const char *v;
|
||||
|
||||
while (xs_list_next(timeline, &v, &c)) {
|
||||
xs_list_foreach(timeline, v) {
|
||||
xs *msg = NULL;
|
||||
|
||||
if (user) {
|
||||
|
@ -3874,10 +3883,14 @@ xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *
|
|||
|
||||
const char *id = xs_dict_get(msg, "id");
|
||||
const char *content = xs_dict_get(msg, "content");
|
||||
const char *published = xs_dict_get(msg, "published");
|
||||
|
||||
if (user && !xs_startswith(id, user->actor))
|
||||
continue;
|
||||
|
||||
if (!id || !content || !published)
|
||||
continue;
|
||||
|
||||
/* create a title with the first line of the content */
|
||||
xs *title = xs_replace(content, "<br>", "\n");
|
||||
title = xs_regex_replace_i(title, "<[^>]+>", " ");
|
||||
|
@ -3893,14 +3906,30 @@ xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *
|
|||
|
||||
title = xs_strip_i(title);
|
||||
|
||||
/* convert the date */
|
||||
time_t t = xs_parse_iso_date(published, 0);
|
||||
xs *rss_date = xs_str_utctime(t, "%a, %d %b %Y %T +0000");
|
||||
|
||||
/* if it's the first one, add it to the header */
|
||||
if (cnt == 0)
|
||||
xs_html_add(channel,
|
||||
xs_html_tag("lastBuildDate",
|
||||
xs_html_text(rss_date)));
|
||||
|
||||
xs_html_add(channel,
|
||||
xs_html_tag("item",
|
||||
xs_html_tag("title",
|
||||
xs_html_text(title)),
|
||||
xs_html_tag("link",
|
||||
xs_html_text(id)),
|
||||
xs_html_tag("guid",
|
||||
xs_html_text(id)),
|
||||
xs_html_tag("pubDate",
|
||||
xs_html_text(rss_date)),
|
||||
xs_html_tag("description",
|
||||
xs_html_text(content))));
|
||||
|
||||
cnt++;
|
||||
}
|
||||
|
||||
return xs_html_render_s(rss, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
|
||||
|
|
3
snac.h
3
snac.h
|
@ -355,7 +355,8 @@ int html_get_handler(const xs_dict *req, const char *q_path,
|
|||
int html_post_handler(const xs_dict *req, const char *q_path,
|
||||
char *payload, int p_size,
|
||||
char **body, int *b_size, char **ctype);
|
||||
xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc);
|
||||
xs_str *timeline_to_rss(snac *user, const xs_list *timeline,
|
||||
const char *title, const char *link, const char *desc);
|
||||
|
||||
int write_default_css(void);
|
||||
int snac_init(const char *_basedir);
|
||||
|
|
Loading…
Reference in a new issue