summaryrefslogtreecommitdiff
path: root/html.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--html.c78
1 files changed, 45 insertions, 33 deletions
diff --git a/html.c b/html.c
index 5195ba7..43973e8 100644
--- a/html.c
+++ b/html.c
@@ -95,7 +95,7 @@ xs_str *actor_name(xs_dict *actor)
95xs_str *html_actor_icon(xs_dict *actor, const char *date, 95xs_str *html_actor_icon(xs_dict *actor, const char *date,
96 const char *udate, const char *url, int priv) 96 const char *udate, const char *url, int priv)
97{ 97{
98 xs_str *s = xs_str_new(NULL); 98 xs_html *actor_icon = xs_html_tag("p", NULL);
99 99
100 xs *avatar = NULL; 100 xs *avatar = NULL;
101 char *v; 101 char *v;
@@ -111,31 +111,45 @@ xs_str *html_actor_icon(xs_dict *actor, const char *date,
111 if (avatar == NULL) 111 if (avatar == NULL)
112 avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64()); 112 avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64());
113 113
114 { 114 xs_html_add(actor_icon,
115 xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" loading=\"lazy\" " 115 xs_html_sctag("img",
116 "src=\"%s\" alt=\"\"/>\n", avatar); 116 xs_html_attr("loading", "lazy"),
117 s = xs_str_cat(s, s1); 117 xs_html_attr("class", "snac-avatar"),
118 } 118 xs_html_attr("src", avatar),
119 xs_html_attr("alt", "")),
120 xs_html_tag("a",
121 xs_html_attr("href", xs_dict_get(actor, "id")),
122 xs_html_attr("class", "p-author h-card snac-author"),
123 xs_html_raw(name))); /* name is already html-escaped */
119 124
120 {
121 xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>",
122 xs_dict_get(actor, "id"), name);
123 s = xs_str_cat(s, s1);
124 }
125 125
126 if (!xs_is_null(url)) { 126 if (!xs_is_null(url)) {
127 xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", url); 127 xs_html_add(actor_icon,
128 s = xs_str_cat(s, s1); 128 xs_html_text(" "),
129 xs_html_tag("a",
130 xs_html_attr("href", (char *)url),
131 xs_html_text("»")));
129 } 132 }
130 133
131 if (priv) 134 if (priv) {
132 s = xs_str_cat(s, " <span title=\"private\">&#128274;</span>"); 135 xs_html_add(actor_icon,
136 xs_html_text(" "),
137 xs_html_tag("span",
138 xs_html_attr("title", "private"),
139 xs_html_raw("&#128274;")));
140 }
133 141
134 if (strcmp(xs_dict_get(actor, "type"), "Service") == 0) 142 if (strcmp(xs_dict_get(actor, "type"), "Service") == 0) {
135 s = xs_str_cat(s, " <span title=\"bot\">&#129302;</span>"); 143 xs_html_add(actor_icon,
144 xs_html_text(" "),
145 xs_html_tag("span",
146 xs_html_attr("title", "bot"),
147 xs_html_raw("&#129302;")));
148 }
136 149
137 if (xs_is_null(date)) { 150 if (xs_is_null(date)) {
138 s = xs_str_cat(s, "\n&nbsp;\n"); 151 xs_html_add(actor_icon,
152 xs_html_raw("&nbsp;"));
139 } 153 }
140 else { 154 else {
141 xs *date_label = xs_crop_i(xs_dup(date), 0, 10); 155 xs *date_label = xs_crop_i(xs_dup(date), 0, 10);
@@ -149,18 +163,16 @@ xs_str *html_actor_icon(xs_dict *actor, const char *date,
149 date_title = xs_str_cat(date_title, " / ", udate); 163 date_title = xs_str_cat(date_title, " / ", udate);
150 } 164 }
151 165
152 xs *edt = encode_html(date_title); 166 xs_html_add(actor_icon,
153 xs *edl = encode_html(date_label); 167 xs_html_text(" "),
154 xs *s1 = xs_fmt( 168 xs_html_tag("time",
155 "\n<time class=\"dt-published snac-pubdate\" title=\"%s\">%s</time>\n", 169 xs_html_attr("class", "dt-published snac-pubdate"),
156 edt, edl); 170 xs_html_attr("title", date_title),
157 171 xs_html_text(date_label)));
158 s = xs_str_cat(s, s1);
159 } 172 }
160 173
161 { 174 {
162 char *username, *id; 175 char *username, *id;
163 xs *s1;
164 176
165 if (xs_is_null(username = xs_dict_get(actor, "preferredUsername")) || *username == '\0') { 177 if (xs_is_null(username = xs_dict_get(actor, "preferredUsername")) || *username == '\0') {
166 /* This should never be reached */ 178 /* This should never be reached */
@@ -176,15 +188,15 @@ xs_str *html_actor_icon(xs_dict *actor, const char *date,
176 xs *domain = xs_split(id, "/"); 188 xs *domain = xs_split(id, "/");
177 xs *user = xs_fmt("@%s@%s", username, xs_list_get(domain, 2)); 189 xs *user = xs_fmt("@%s@%s", username, xs_list_get(domain, 2));
178 190
179 xs *u1 = encode_html(user); 191 xs_html_add(actor_icon,
180 s1 = xs_fmt( 192 xs_html_sctag("br", NULL),
181 "<br><a href=\"%s\" class=\"p-author-tag h-card snac-author-tag\">%s</a>", 193 xs_html_tag("a",
182 xs_dict_get(actor, "id"), u1); 194 xs_html_attr("href", xs_dict_get(actor, "id")),
183 195 xs_html_attr("class", "p-author-tag h-card snac-author-tag"),
184 s = xs_str_cat(s, s1); 196 xs_html_text(user)));
185 } 197 }
186 198
187 return s; 199 return xs_html_render(actor_icon);
188} 200}
189 201
190 202