html_timeline() now uses xs_html.

This commit is contained in:
default 2023-11-29 10:14:37 +01:00
parent 6c6dd060eb
commit b1a9279f85
2 changed files with 40 additions and 48 deletions

75
html.c
View file

@ -2059,24 +2059,39 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
int skip, int show, int show_more, char *tag) int skip, int show, int show_more, char *tag)
/* returns the HTML for the timeline */ /* returns the HTML for the timeline */
{ {
xs_str *s = xs_str_new(NULL);
xs_list *p = (xs_list *)list; xs_list *p = (xs_list *)list;
char *v; char *v;
double t = ftime(); double t = ftime();
if (user) xs_html *head;
s = html_user_header(user, s, local); xs_html *body;
else
s = html_instance_header(s, tag);
if (user && !local) { if (user) {
xs_html *h = html_top_controls(user); head = html_user_head(user);
xs *s1 = xs_html_render(h); body = html_user_body(user, local);
s = xs_str_cat(s, s1); }
else {
head = html_instance_head();
body = html_instance_body(tag);
} }
s = xs_str_cat(s, "<a name=\"snac-posts\"></a>\n"); xs_html *html = xs_html_tag("html",
s = xs_str_cat(s, "<div class=\"snac-posts\">\n"); head,
body);
if (user && !local)
xs_html_add(body,
html_top_controls(user));
xs_html_add(body,
xs_html_tag("a",
xs_html_attr("name", "snac-posts")));
xs_html *posts = xs_html_tag("div",
xs_html_attr("class", "snac-posts"));
xs_html_add(body,
posts);
while (xs_list_iter(&p, &v)) { while (xs_list_iter(&p, &v)) {
xs *msg = NULL; xs *msg = NULL;
@ -2111,19 +2126,13 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1); xs_html *entry = html_entry(user, msg, local, 0, v, user ? 0 : 1);
if (entry != NULL) { if (entry != NULL)
xs *s1 = xs_html_render(entry); xs_html_add(posts,
s = xs_str_cat(s, s1); entry);
} }
}
s = xs_str_cat(s, "</div>\n");
if (list && user && local) { if (list && user && local) {
if (xs_type(xs_dict_get(srv_config, "disable_history")) == XSTYPE_TRUE) { if (xs_type(xs_dict_get(srv_config, "disable_history")) != XSTYPE_TRUE) {
s = xs_str_cat(s, "<!-- history disabled -->\n");
}
else {
xs_html *ul = xs_html_tag("ul", NULL); xs_html *ul = xs_html_tag("ul", NULL);
xs_html *history = xs_html_tag("div", xs_html *history = xs_html_tag("div",
@ -2148,14 +2157,15 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
xs_html_text(fn)))); xs_html_text(fn))));
} }
xs *s1 = xs_html_render(history); xs_html_add(body,
s = xs_str_cat(s, s1); history);
} }
} }
{ {
xs *s1 = xs_fmt("<!-- %lf seconds -->\n", ftime() - t); xs *s1 = xs_fmt("\n<!-- %lf seconds -->\n", ftime() - t);
s = xs_str_cat(s, s1); xs_html_add(body,
xs_html_raw(s1));
} }
if (show_more) { if (show_more) {
@ -2183,19 +2193,14 @@ xs_str *html_timeline(snac *user, const xs_list *list, int local,
xs_html_attr("name", "snac-more"), xs_html_attr("name", "snac-more"),
xs_html_text(L("More...")))); xs_html_text(L("More..."))));
xs *s1 = xs_html_render(more_links); xs_html_add(body,
s = xs_str_cat(s, s1); more_links);
} }
{ xs_html_add(body,
xs_html *h = html_footer(); html_footer());
xs *s1 = xs_html_render(h);
s = xs_str_cat(s, s1);
}
s = xs_str_cat(s, "</body>\n</html>\n"); return xs_html_render_s(html, "<!DOCTYPE html>\n");
return s;
} }

13
main.c
View file

@ -209,19 +209,6 @@ int main(int argc, char *argv[])
srv_free(); srv_free();
#endif #endif
{
xs_html *note = html_note(&snac, "Note...",
"DIV_ID", "FORM_ID",
"TEXTAREA_PLACEHOLDER", "TEXTAREA_CONTENT",
"EDIT_ID", "ACTOR_ID",
xs_stock_false, "CW_TEXT",
xs_stock_false, "REDIR",
"IN_REPLY_TO", 1);
xs *s1 = xs_html_render(note);
printf("\n%s\n", s1);
}
xs *idx = xs_fmt("%s/private.idx", snac.basedir); xs *idx = xs_fmt("%s/private.idx", snac.basedir);
xs *list = index_list_desc(idx, 0, 256); xs *list = index_list_desc(idx, 0, 256);
xs *tl = timeline_top_level(&snac, list); xs *tl = timeline_top_level(&snac, list);