commit 179a7ae

default  ·  2023-11-28 09:13:27 +0000 UTC
parent 5d3b22b
Converted top_nav to xs_html.
1 files changed,  +53, -30
M html.c
M html.c
+53, -30
  1@@ -668,7 +668,8 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local)
  2     s = xs_str_cat(s, "\n<body>\n");
  3 
  4     /* top nav */
  5-    s = xs_str_cat(s, "<nav class=\"snac-top-nav\">");
  6+    xs_html *top_nav = xs_html_tag("nav",
  7+        xs_html_attr("class", "snac-top-nav"));
  8 
  9     xs *avatar = xs_dup(xs_dict_get(snac->config, "avatar"));
 10 
 11@@ -677,46 +678,68 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local)
 12         avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64());
 13     }
 14 
 15-    {
 16-        xs *s1;
 17-
 18-        s1 = xs_fmt("<img src=\"%s\" class=\"snac-avatar\" alt=\"\"/>&nbsp;", avatar);
 19-
 20-        s = xs_str_cat(s, s1);
 21-    }
 22+    xs_html_add(top_nav,
 23+        xs_html_sctag("img",
 24+            xs_html_attr("src", avatar),
 25+            xs_html_attr("class", "snac-avatar"),
 26+            xs_html_attr("alt", "")));
 27 
 28     {
 29-        xs *s1;
 30-
 31-        if (local)
 32-            s1 = xs_fmt(
 33-                "<a href=\"%s.rss\">%s</a> - "
 34-                "<a href=\"%s/admin\" rel=\"nofollow\">%s</a></nav>\n",
 35-                snac->actor, L("RSS"),
 36-                snac->actor, L("private"));
 37+        if (local) {
 38+            xs *rss_url = xs_fmt("%s.rss", snac->actor);
 39+            xs *admin_url = xs_fmt("%s/admin", snac->actor);
 40+
 41+            xs_html_add(top_nav,
 42+                xs_html_tag("a",
 43+                    xs_html_attr("href", rss_url),
 44+                    xs_html_text(L("RSS"))),
 45+                xs_html_text(" - "),
 46+                xs_html_tag("a",
 47+                    xs_html_attr("href", admin_url),
 48+                    xs_html_attr("rel", "nofollow"),
 49+                    xs_html_text(L("private"))));
 50+        }
 51         else {
 52             xs *n_list = notify_list(snac, 1);
 53             int n_len  = xs_list_len(n_list);
 54             xs *n_str  = NULL;
 55+            xs_html *notify_count = NULL;
 56 
 57             /* show the number of new notifications, if there are any */
 58-            if (n_len)
 59-                n_str = xs_fmt("<sup style=\"background-color: red; "
 60-                               "color: white;\"> %d </sup> ", n_len);
 61+            if (n_len) {
 62+                xs *n_len_str = xs_fmt(" %d ", n_len);
 63+                notify_count = xs_html_tag("sup",
 64+                    xs_html_attr("style", "background-color: red; color: white;"),
 65+                    xs_html_text(n_len_str));
 66+            }
 67             else
 68-                n_str = xs_str_new("");
 69-
 70-            s1 = xs_fmt(
 71-                "<a href=\"%s\">%s</a> - "
 72-                "<a href=\"%s/admin\">%s</a> - "
 73-                "<a href=\"%s/notifications\">%s</a>%s - "
 74-                "<a href=\"%s/people\">%s</a></nav>\n",
 75-                snac->actor, L("public"),
 76-                snac->actor, L("private"),
 77-                snac->actor, L("notifications"), n_str,
 78-                snac->actor, L("people"));
 79+                notify_count = xs_html_text("");
 80+
 81+            xs *admin_url = xs_fmt("%s/admin", snac->actor);
 82+            xs *notify_url = xs_fmt("%s/notifications", snac->actor);
 83+            xs *people_url = xs_fmt("%s/people", snac->actor);
 84+            xs_html_add(top_nav,
 85+                xs_html_tag("a",
 86+                    xs_html_attr("href", snac->actor),
 87+                    xs_html_text(L("public"))),
 88+                xs_html_text(" - "),
 89+                xs_html_tag("a",
 90+                    xs_html_attr("href", admin_url),
 91+                    xs_html_text(L("private"))),
 92+                xs_html_text(" - "),
 93+                xs_html_tag("a",
 94+                    xs_html_attr("href", notify_url),
 95+                    xs_html_text(L("notifications"))),
 96+                notify_count,
 97+                xs_html_text(" - "),
 98+                xs_html_tag("a",
 99+                    xs_html_attr("href", people_url),
100+                    xs_html_text(L("people"))));
101         }
102+    }
103 
104+    {
105+        xs *s1 = xs_html_render(top_nav);
106         s = xs_str_cat(s, s1);
107     }
108