commit 82ec4ea

default  ·  2024-05-07 18:32:13 +0000 UTC
parent b57409a
Minor "Back to top" "More..." link refactoring.
3 files changed,  +22, -24
M html.c
M snac.h
M html.c
+14, -20
 1@@ -509,7 +509,7 @@ xs_html *html_instance_head(void)
 2 }
 3 
 4 
 5-static xs_html *html_instance_body(char *tag)
 6+static xs_html *html_instance_body(char *title)
 7 {
 8     char *host  = xs_dict_get(srv_config, "host");
 9     char *sdesc = xs_dict_get(srv_config, "short_description");
10@@ -560,14 +560,11 @@ static xs_html *html_instance_body(char *tag)
11                         xs_html_text(handle)))));
12     }
13 
14-    {
15-        xs *l = tag ? xs_fmt(L("Search results for #%s"), tag) :
16-            xs_dup(L("Recent posts by users in this instance"));
17-
18+    if (title != NULL) {
19         xs_html_add(body,
20             xs_html_tag("h2",
21                 xs_html_attr("class", "snac-header"),
22-                xs_html_text(l)));
23+                xs_html_text(title)));
24     }
25 
26     return body;
27@@ -1996,7 +1993,7 @@ xs_html *html_footer(void)
28 
29 xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
30                       int skip, int show, int show_more,
31-                      char *tag, char *page, int utl)
32+                      char *title, char *page, int utl)
33 /* returns the HTML for the timeline */
34 {
35     xs_list *p = (xs_list *)list;
36@@ -2026,7 +2023,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
37     }
38     else {
39         head = html_instance_head();
40-        body = html_instance_body(tag);
41+        body = html_instance_body(title);
42     }
43 
44     xs_html *html = xs_html_tag("html",
45@@ -2126,25 +2123,22 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
46     }
47 
48     if (show_more) {
49-        xs *t  = NULL;
50         xs *m  = NULL;
51         xs *ss = xs_fmt("skip=%d&show=%d", skip + show, show);
52 
53-        xs *url = page == NULL || user == NULL ?
54-            xs_dup(srv_baseurl) : xs_fmt("%s%s", user->actor, page);
55+        xs *url = xs_dup(user == NULL ? srv_baseurl : user->actor);
56 
57-        if (tag) {
58-            t = xs_fmt("%s?t=%s", url, tag);
59-            m = xs_fmt("%s&%s", t, ss);
60-        }
61-        else {
62-            t = xs_dup(url);
63-            m = xs_fmt("%s?%s", t, ss);
64-        }
65+        if (page != NULL)
66+            url = xs_str_cat(url, page);
67+
68+        if (xs_str_in(url, "?") != -1)
69+            m = xs_fmt("%s&%s", url, ss);
70+        else
71+            m = xs_fmt("%s?%s", url, ss);
72 
73         xs_html *more_links = xs_html_tag("p",
74             xs_html_tag("a",
75-                xs_html_attr("href", t),
76+                xs_html_attr("href", url),
77                 xs_html_attr("name", "snac-more"),
78                 xs_html_text(L("Back to top"))),
79             xs_html_text(" - "),
+7, -3
 1@@ -200,14 +200,18 @@ int server_get_handler(xs_dict *req, const char *q_path,
 2                 *body = timeline_to_rss(NULL, tl, link, link, link);
 3                 *ctype = "application/rss+xml; charset=utf-8";
 4             }
 5-            else
 6-                *body = html_timeline(NULL, tl, 0, skip, show, more, t, NULL, 0);
 7+            else {
 8+                xs *page = xs_fmt("?t=%s", t);
 9+                xs *title = xs_fmt(L("Search results for #%s"), t);
10+                *body = html_timeline(NULL, tl, 0, skip, show, more, title, page, 0);
11+            }
12         }
13         else
14         if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) {
15             /** instance timeline **/
16             xs *tl = timeline_instance_list(0, 30);
17-            *body = html_timeline(NULL, tl, 0, 0, 0, 0, NULL, NULL, 0);
18+            *body = html_timeline(NULL, tl, 0, 0, 0, 0,
19+                L("Recent posts by users in this instance"), NULL, 0);
20         }
21         else
22             *body = greeting_html();
M snac.h
+1, -1
1@@ -318,7 +318,7 @@ xs_str *encode_html(const char *str);
2 
3 xs_str *html_timeline(snac *user, const xs_list *list, int read_only,
4                       int skip, int show, int show_more,
5-                      char *tag, char *page, int utl);
6+                      char *title, char *page, int utl);
7 
8 int html_get_handler(const xs_dict *req, const char *q_path,
9                      char **body, int *b_size, char **ctype, xs_str **etag);