From c963a29923fce0a4689f7c71e0c1c46d059382db Mon Sep 17 00:00:00 2001 From: default Date: Tue, 28 Nov 2023 10:55:12 +0100 Subject: More xs_html refactoring. --- html.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) (limited to 'html.c') diff --git a/html.c b/html.c index 2fd0bbd..19fb58b 100644 --- a/html.c +++ b/html.c @@ -745,29 +745,33 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local) /* user info */ { - s = xs_str_cat(s, "
\n"); + xs_html *top_user = xs_html_tag("div", + xs_html_attr("class", "h-card snac-top-user")); if (local) { - const char *header = xs_dict_get(snac->config, "header"); + char *header = xs_dict_get(snac->config, "header"); if (header && *header) { - xs *h = encode_html(header); - xs *s1 = xs_fmt("
" - "
\n", h); - s = xs_str_cat(s, s1); + xs_html_add(top_user, + xs_html_tag("div", + xs_html_attr("class", "snac-top-user-banner"), + xs_html_attr("style", "clear: both"), + xs_html_sctag("br", NULL), + xs_html_sctag("img", + xs_html_attr("src", header)))); } } - const char *_tmpl = - "

%s

\n" - "

@%s@%s

\n"; - - xs *es1 = encode_html(xs_dict_get(snac->config, "name")); - xs *es2 = encode_html(xs_dict_get(snac->config, "uid")); - xs *es3 = encode_html(xs_dict_get(srv_config, "host")); - - xs *s1 = xs_fmt(_tmpl, es1, es2, es3); + xs *handle = xs_fmt("@%s@%s", + xs_dict_get(snac->config, "uid"), + xs_dict_get(srv_config, "host")); - s = xs_str_cat(s, s1); + xs_html_add(top_user, + xs_html_tag("p", + xs_html_attr("class", "p-name snac-top-user-name"), + xs_html_text(xs_dict_get(snac->config, "name"))), + xs_html_tag("p", + xs_html_attr("class", "snac-top-user-id"), + xs_html_text(handle))); if (local) { xs *es1 = encode_html(xs_dict_get(snac->config, "bio")); @@ -779,10 +783,8 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local) xs_html_attr("class", "p-note snac-top-user-bio"), xs_html_raw(bio2)); /* already sanitized */ - { - xs *s1 = xs_html_render(top_user_bio); - s = xs_str_cat(s, s1); - } + xs_html_add(top_user, + top_user_bio); xs_dict *metadata = xs_dict_get(snac->config, "metadata"); if (xs_type(metadata) == XSTYPE_DICT) { @@ -814,14 +816,15 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local) xs_html_sctag("br", NULL)); } - { - xs *s1 = xs_html_render(snac_metadata); - s = xs_str_cat(s, s1); - } + xs_html_add(top_user, + snac_metadata); } } - s = xs_str_cat(s, "
\n"); + { + xs *s1 = xs_html_render(top_user); + s = xs_str_cat(s, s1); + } } return s; -- cgit v1.2.3