summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
authorGravatar default2024-11-10 06:59:55 +0100
committerGravatar default2024-11-10 06:59:55 +0100
commitd9b94a556a8f74613737e940871daf95bd1330fd (patch)
tree1ab5b3f14147facc8f78068dc99c46b066527341 /html.c
parentMerge pull request 'Fix "empty input line" warning by groff' (#222) from serg... (diff)
downloadsnac2-d9b94a556a8f74613737e940871daf95bd1330fd.tar.gz
snac2-d9b94a556a8f74613737e940871daf95bd1330fd.tar.xz
snac2-d9b94a556a8f74613737e940871daf95bd1330fd.zip
RSS feeds are now 2.0 instead of 0.91.
Diffstat (limited to 'html.c')
-rw-r--r--html.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/html.c b/html.c
index 3721f0e..535be01 100644
--- a/html.c
+++ b/html.c
@@ -3839,11 +3839,14 @@ int html_post_handler(const xs_dict *req, const char *q_path,
3839} 3839}
3840 3840
3841 3841
3842xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc) 3842xs_str *timeline_to_rss(snac *user, const xs_list *timeline,
3843 const char *title, const char *link, const char *desc)
3843/* converts a timeline to rss */ 3844/* converts a timeline to rss */
3844{ 3845{
3845 xs_html *rss = xs_html_tag("rss", 3846 xs_html *rss = xs_html_tag("rss",
3846 xs_html_attr("version", "0.91")); 3847 xs_html_attr("xmlns:content", "http:/" "/purl.org/rss/1.0/modules/content/"),
3848 xs_html_attr("version", "2.0"),
3849 xs_html_attr("xmlns:atom", "http:/" "/www.w3.org/2005/Atom"));
3847 3850
3848 xs_html *channel = xs_html_tag("channel", 3851 xs_html *channel = xs_html_tag("channel",
3849 xs_html_tag("title", 3852 xs_html_tag("title",
@@ -3852,15 +3855,21 @@ xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *
3852 xs_html_text("en")), 3855 xs_html_text("en")),
3853 xs_html_tag("link", 3856 xs_html_tag("link",
3854 xs_html_text(link)), 3857 xs_html_text(link)),
3858 xs_html_sctag("atom:link",
3859 xs_html_attr("href", link),
3860 xs_html_attr("rel", "self"),
3861 xs_html_attr("type", "application/rss+xml")),
3862 xs_html_tag("generator",
3863 xs_html_text(USER_AGENT)),
3855 xs_html_tag("description", 3864 xs_html_tag("description",
3856 xs_html_text(desc))); 3865 xs_html_text(desc)));
3857 3866
3858 xs_html_add(rss, channel); 3867 xs_html_add(rss, channel);
3859 3868
3860 int c = 0; 3869 int cnt = 0;
3861 const char *v; 3870 const char *v;
3862 3871
3863 while (xs_list_next(timeline, &v, &c)) { 3872 xs_list_foreach(timeline, v) {
3864 xs *msg = NULL; 3873 xs *msg = NULL;
3865 3874
3866 if (user) { 3875 if (user) {
@@ -3874,10 +3883,14 @@ xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *
3874 3883
3875 const char *id = xs_dict_get(msg, "id"); 3884 const char *id = xs_dict_get(msg, "id");
3876 const char *content = xs_dict_get(msg, "content"); 3885 const char *content = xs_dict_get(msg, "content");
3886 const char *published = xs_dict_get(msg, "published");
3877 3887
3878 if (user && !xs_startswith(id, user->actor)) 3888 if (user && !xs_startswith(id, user->actor))
3879 continue; 3889 continue;
3880 3890
3891 if (!id || !content || !published)
3892 continue;
3893
3881 /* create a title with the first line of the content */ 3894 /* create a title with the first line of the content */
3882 xs *title = xs_replace(content, "<br>", "\n"); 3895 xs *title = xs_replace(content, "<br>", "\n");
3883 title = xs_regex_replace_i(title, "<[^>]+>", " "); 3896 title = xs_regex_replace_i(title, "<[^>]+>", " ");
@@ -3893,14 +3906,30 @@ xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *
3893 3906
3894 title = xs_strip_i(title); 3907 title = xs_strip_i(title);
3895 3908
3909 /* convert the date */
3910 time_t t = xs_parse_iso_date(published, 0);
3911 xs *rss_date = xs_str_utctime(t, "%a, %d %b %Y %T +0000");
3912
3913 /* if it's the first one, add it to the header */
3914 if (cnt == 0)
3915 xs_html_add(channel,
3916 xs_html_tag("lastBuildDate",
3917 xs_html_text(rss_date)));
3918
3896 xs_html_add(channel, 3919 xs_html_add(channel,
3897 xs_html_tag("item", 3920 xs_html_tag("item",
3898 xs_html_tag("title", 3921 xs_html_tag("title",
3899 xs_html_text(title)), 3922 xs_html_text(title)),
3900 xs_html_tag("link", 3923 xs_html_tag("link",
3901 xs_html_text(id)), 3924 xs_html_text(id)),
3925 xs_html_tag("guid",
3926 xs_html_text(id)),
3927 xs_html_tag("pubDate",
3928 xs_html_text(rss_date)),
3902 xs_html_tag("description", 3929 xs_html_tag("description",
3903 xs_html_text(content)))); 3930 xs_html_text(content))));
3931
3932 cnt++;
3904 } 3933 }
3905 3934
3906 return xs_html_render_s(rss, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 3935 return xs_html_render_s(rss, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");