commit b1a9279

default  ·  2023-11-29 09:14:37 +0000 UTC
parent 6c6dd06
html_timeline() now uses xs_html.
2 files changed,  +40, -48
M html.c
M main.c
M html.c
+40, -35
  1@@ -2059,24 +2059,39 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
  2                       int skip, int show, int show_more, char *tag)
  3 /* returns the HTML for the timeline */
  4 {
  5-    xs_str *s = xs_str_new(NULL);
  6     xs_list *p = (xs_list *)list;
  7     char *v;
  8     double t = ftime();
  9 
 10-    if (user)
 11-        s = html_user_header(user, s, local);
 12-    else
 13-        s = html_instance_header(s, tag);
 14+    xs_html *head;
 15+    xs_html *body;
 16 
 17-    if (user && !local) {
 18-        xs_html *h = html_top_controls(user);
 19-        xs *s1 = xs_html_render(h);
 20-        s = xs_str_cat(s, s1);
 21+    if (user) {
 22+        head = html_user_head(user);
 23+        body = html_user_body(user, local);
 24+    }
 25+    else {
 26+        head = html_instance_head();
 27+        body = html_instance_body(tag);
 28     }
 29 
 30-    s = xs_str_cat(s, "<a name=\"snac-posts\"></a>\n");
 31-    s = xs_str_cat(s, "<div class=\"snac-posts\">\n");
 32+    xs_html *html = xs_html_tag("html",
 33+        head,
 34+        body);
 35+
 36+    if (user && !local)
 37+        xs_html_add(body,
 38+            html_top_controls(user));
 39+
 40+    xs_html_add(body,
 41+        xs_html_tag("a",
 42+            xs_html_attr("name", "snac-posts")));
 43+
 44+    xs_html *posts = xs_html_tag("div",
 45+        xs_html_attr("class", "snac-posts"));
 46+
 47+    xs_html_add(body,
 48+        posts);
 49 
 50     while (xs_list_iter(&p, &v)) {
 51         xs *msg = NULL;
 52@@ -2111,19 +2126,13 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
 53 
 54         xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1);
 55 
 56-        if (entry != NULL) {
 57-            xs *s1 = xs_html_render(entry);
 58-            s = xs_str_cat(s, s1);
 59-        }
 60+        if (entry != NULL)
 61+            xs_html_add(posts,
 62+                entry);
 63     }
 64 
 65-    s = xs_str_cat(s, "</div>\n");
 66-
 67     if (list && user && local) {
 68-        if (xs_type(xs_dict_get(srv_config, "disable_history")) == XSTYPE_TRUE) {
 69-            s = xs_str_cat(s, "<!-- history disabled -->\n");
 70-        }
 71-        else {
 72+        if (xs_type(xs_dict_get(srv_config, "disable_history")) != XSTYPE_TRUE) {
 73             xs_html *ul = xs_html_tag("ul", NULL);
 74 
 75             xs_html *history = xs_html_tag("div",
 76@@ -2148,14 +2157,15 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
 77                             xs_html_text(fn))));
 78             }
 79 
 80-            xs *s1 = xs_html_render(history);
 81-            s = xs_str_cat(s, s1);
 82+            xs_html_add(body,
 83+                history);
 84         }
 85     }
 86 
 87     {
 88-        xs *s1 = xs_fmt("<!-- %lf seconds -->\n", ftime() - t);
 89-        s = xs_str_cat(s, s1);
 90+        xs *s1 = xs_fmt("\n<!-- %lf seconds -->\n", ftime() - t);
 91+        xs_html_add(body,
 92+            xs_html_raw(s1));
 93     }
 94 
 95     if (show_more) {
 96@@ -2183,19 +2193,14 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
 97                 xs_html_attr("name", "snac-more"),
 98                 xs_html_text(L("More..."))));
 99 
100-        xs *s1 = xs_html_render(more_links);
101-        s = xs_str_cat(s, s1);
102-    }
103-
104-    {
105-        xs_html *h = html_footer();
106-        xs *s1 = xs_html_render(h);
107-        s = xs_str_cat(s, s1);
108+        xs_html_add(body,
109+            more_links);
110     }
111 
112-    s = xs_str_cat(s, "</body>\n</html>\n");
113+    xs_html_add(body,
114+        html_footer());
115 
116-    return s;
117+    return xs_html_render_s(html, "<!DOCTYPE html>\n");
118 }
119 
120 
M main.c
+0, -13
 1@@ -209,19 +209,6 @@ int main(int argc, char *argv[])
 2         srv_free();
 3 #endif
 4 
 5-        {
 6-            xs_html *note = html_note(&snac, "Note...",
 7-                "DIV_ID", "FORM_ID",
 8-                "TEXTAREA_PLACEHOLDER", "TEXTAREA_CONTENT",
 9-                "EDIT_ID", "ACTOR_ID",
10-                xs_stock_false, "CW_TEXT",
11-                xs_stock_false, "REDIR",
12-                "IN_REPLY_TO", 1);
13-
14-            xs *s1 = xs_html_render(note);
15-            printf("\n%s\n", s1);
16-        }
17-
18         xs *idx  = xs_fmt("%s/private.idx", snac.basedir);
19         xs *list = index_list_desc(idx, 0, 256);
20         xs *tl   = timeline_top_level(&snac, list);