From 82ec4ea95cb1040c5b9b983ec649dbde024d20f8 Mon Sep 17 00:00:00 2001 From: default Date: Tue, 7 May 2024 20:32:13 +0200 Subject: [PATCH] Minor "Back to top" "More..." link refactoring. --- html.c | 34 ++++++++++++++-------------------- httpd.c | 10 +++++++--- snac.h | 2 +- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/html.c b/html.c index 536879c..bd3179d 100644 --- a/html.c +++ b/html.c @@ -509,7 +509,7 @@ xs_html *html_instance_head(void) } -static xs_html *html_instance_body(char *tag) +static xs_html *html_instance_body(char *title) { char *host = xs_dict_get(srv_config, "host"); char *sdesc = xs_dict_get(srv_config, "short_description"); @@ -560,14 +560,11 @@ static xs_html *html_instance_body(char *tag) xs_html_text(handle))))); } - { - xs *l = tag ? xs_fmt(L("Search results for #%s"), tag) : - xs_dup(L("Recent posts by users in this instance")); - + if (title != NULL) { xs_html_add(body, xs_html_tag("h2", xs_html_attr("class", "snac-header"), - xs_html_text(l))); + xs_html_text(title))); } return body; @@ -1996,7 +1993,7 @@ xs_html *html_footer(void) xs_str *html_timeline(snac *user, const xs_list *list, int read_only, int skip, int show, int show_more, - char *tag, char *page, int utl) + char *title, char *page, int utl) /* returns the HTML for the timeline */ { xs_list *p = (xs_list *)list; @@ -2026,7 +2023,7 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, } else { head = html_instance_head(); - body = html_instance_body(tag); + body = html_instance_body(title); } xs_html *html = xs_html_tag("html", @@ -2126,25 +2123,22 @@ xs_str *html_timeline(snac *user, const xs_list *list, int read_only, } if (show_more) { - xs *t = NULL; xs *m = NULL; xs *ss = xs_fmt("skip=%d&show=%d", skip + show, show); - xs *url = page == NULL || user == NULL ? - xs_dup(srv_baseurl) : xs_fmt("%s%s", user->actor, page); + xs *url = xs_dup(user == NULL ? srv_baseurl : user->actor); - if (tag) { - t = xs_fmt("%s?t=%s", url, tag); - m = xs_fmt("%s&%s", t, ss); - } - else { - t = xs_dup(url); - m = xs_fmt("%s?%s", t, ss); - } + if (page != NULL) + url = xs_str_cat(url, page); + + if (xs_str_in(url, "?") != -1) + m = xs_fmt("%s&%s", url, ss); + else + m = xs_fmt("%s?%s", url, ss); xs_html *more_links = xs_html_tag("p", xs_html_tag("a", - xs_html_attr("href", t), + xs_html_attr("href", url), xs_html_attr("name", "snac-more"), xs_html_text(L("Back to top"))), xs_html_text(" - "), diff --git a/httpd.c b/httpd.c index 30367c8..81b0853 100644 --- a/httpd.c +++ b/httpd.c @@ -200,14 +200,18 @@ int server_get_handler(xs_dict *req, const char *q_path, *body = timeline_to_rss(NULL, tl, link, link, link); *ctype = "application/rss+xml; charset=utf-8"; } - else - *body = html_timeline(NULL, tl, 0, skip, show, more, t, NULL, 0); + else { + xs *page = xs_fmt("?t=%s", t); + xs *title = xs_fmt(L("Search results for #%s"), t); + *body = html_timeline(NULL, tl, 0, skip, show, more, title, page, 0); + } } else if (xs_type(xs_dict_get(srv_config, "show_instance_timeline")) == XSTYPE_TRUE) { /** instance timeline **/ xs *tl = timeline_instance_list(0, 30); - *body = html_timeline(NULL, tl, 0, 0, 0, 0, NULL, NULL, 0); + *body = html_timeline(NULL, tl, 0, 0, 0, 0, + L("Recent posts by users in this instance"), NULL, 0); } else *body = greeting_html(); diff --git a/snac.h b/snac.h index ab8fc7c..2a988f1 100644 --- a/snac.h +++ b/snac.h @@ -318,7 +318,7 @@ xs_str *encode_html(const char *str); xs_str *html_timeline(snac *user, const xs_list *list, int read_only, int skip, int show, int show_more, - char *tag, char *page, int utl); + char *title, char *page, int utl); int html_get_handler(const xs_dict *req, const char *q_path, char **body, int *b_size, char **ctype, xs_str **etag);