More HTML work.

This commit is contained in:
default 2022-09-28 17:12:39 +02:00
parent 7ae3064210
commit 5647e675fd

67
html.c
View file

@ -175,7 +175,7 @@ d_char *html_msg_icon(snac *snac, d_char *s, char *msg)
avatar = xs_fmt("data:image/png;base64, %s", susie); avatar = xs_fmt("data:image/png;base64, %s", susie);
{ {
xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\"/>\n", avatar); xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" src=\"%s\" alt=\"\"/>\n", avatar);
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
} }
@ -200,8 +200,6 @@ d_char *html_msg_icon(snac *snac, d_char *s, char *msg)
xs *s1 = xs_fmt("<br>\n<time class=\"dt-published snac-pubdate\">%s</time>\n", v); xs *s1 = xs_fmt("<br>\n<time class=\"dt-published snac-pubdate\">%s</time>\n", v);
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
} }
s = xs_str_cat(s, "</div>\n");
} }
return s; return s;
@ -425,6 +423,8 @@ d_char *html_entry(snac *snac, d_char *s, char *msg, xs_set *seen, int level)
s = html_msg_icon(snac, s, msg); s = html_msg_icon(snac, s, msg);
/* add the content */ /* add the content */
s = xs_str_cat(s, "<div class=\"e-content snac-content\">\n");
{ {
xs *c = xs_dup(xs_dict_get(msg, "content")); xs *c = xs_dup(xs_dict_get(msg, "content"));
@ -441,32 +441,59 @@ d_char *html_entry(snac *snac, d_char *s, char *msg, xs_set *seen, int level)
c = xs_fmt("<p>%s</p>", s1); c = xs_fmt("<p>%s</p>", s1);
} }
xs *s1 = xs_fmt("<div class=\"e-content snac-content\">\n%s\n", c); s = xs_str_cat(s, c);
s = xs_str_cat(s, s1); }
/* now add the attachments */ /* add the attachments */
char *attach; char *attach;
if ((attach = xs_dict_get(msg, "attachment")) != NULL) { if ((attach = xs_dict_get(msg, "attachment")) != NULL) {
char *v; char *v;
while (xs_list_iter(&attach, &v)) { while (xs_list_iter(&attach, &v)) {
char *t = xs_dict_get(v, "mediaType"); char *t = xs_dict_get(v, "mediaType");
if (t && xs_startswith(t, "image/")) { if (t && xs_startswith(t, "image/")) {
char *url = xs_dict_get(v, "url"); char *url = xs_dict_get(v, "url");
char *name = xs_dict_get(v, "name"); char *name = xs_dict_get(v, "name");
if (url != NULL) { if (url != NULL) {
xs *s1 = xs_fmt("<p><img src=\"%s\" alt=\"%s\"/></p>\n", xs *s1 = xs_fmt("<p><img src=\"%s\" alt=\"%s\"/></p>\n",
url, xs_is_null(name) ? "" : name); url, xs_is_null(name) ? "" : name);
s = xs_str_cat(s, s1); s = xs_str_cat(s, s1);
}
} }
} }
} }
}
s = xs_str_cat(s, "</div> <!-- e-content -->\n"); s = xs_str_cat(s, "</div> <!-- e-content -->\n");
char *children = xs_dict_get(meta, "children");
if (xs_list_len(children)) {
int left = xs_list_len(children);
char *id;
s = xs_str_cat(s, "<div class=\"snac-children\">\n");
if (left > 3)
s = xs_str_cat(s, "<details><summary>...</summary>\n");
while (xs_list_iter(&children, &id)) {
xs *chd = timeline_find(snac, id);
if (left == 0)
s = xs_str_cat(s, "</details>\n");
if (chd != NULL)
s = html_entry(snac, s, chd, seen, level + 1);
else
snac_debug(snac, 1, xs_fmt("cannot read from timeline child %s", id));
left--;
}
s = xs_str_cat(s, "</div> <!-- snac-children -->\n");
} }
s = xs_str_cat(s, "</div> <!-- post or child -->\n"); s = xs_str_cat(s, "</div> <!-- post or child -->\n");