commit 4ab22b2
default
·
2023-07-13 21:41:22 +0000 UTC
parent 64d3bb7
If a Page has an image, show it as an attachment.
1 files changed,
+23,
-3
M
html.c
M
html.c
+23,
-3
1@@ -1146,9 +1146,10 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
2 s = xs_str_cat(s, "\n");
3
4 /* add the attachments */
5- char *attach;
6+ xs_list *attach = xs_dict_get(msg, "attachment");
7+ xs_dict *image = xs_dict_get(msg, "image");
8
9- if ((attach = xs_dict_get(msg, "attachment")) != NULL) { /** **/
10+ if (!xs_is_null(attach) || !xs_is_null(image)) { /** **/
11 char *v;
12
13 /* make custom css for attachments easier */
14@@ -1173,7 +1174,8 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
15
16 xs *es1 = encode_html(name);
17 xs *s1 = xs_fmt(
18- "<a href=\"%s\" target=\"_blank\"><img src=\"%s\" alt=\"%s\" title=\"%s\" loading=\"lazy\"/></a>\n",
19+ "<a href=\"%s\" target=\"_blank\">"
20+ "<img src=\"%s\" alt=\"%s\" title=\"%s\" loading=\"lazy\"/></a>\n",
21 url, url, es1, es1);
22
23 s = xs_str_cat(s, s1);
24@@ -1239,6 +1241,24 @@ xs_str *html_entry(snac *snac, xs_str *os, const xs_dict *msg, int local,
25 }
26 }
27
28+ /* if the message has an image, add it */
29+ if (!xs_is_null(image)) {
30+ if (!xs_is_null(image = xs_dict_get(image, "url"))) {
31+ xs *es1;
32+ if (!xs_is_null(v = xs_dict_get(msg, "name")))
33+ es1 = encode_html(v);
34+ else
35+ es1 = xs_str_new(NULL);
36+
37+ xs *s1 = xs_fmt(
38+ "<a href=\"%s\" target=\"_blank\">"
39+ "<img src=\"%s\" alt=\"%s\" title=\"%s\" loading=\"lazy\"/></a>\n",
40+ image, image, es1, es1);
41+
42+ s = xs_str_cat(s, s1);
43+ }
44+ }
45+
46 s = xs_str_cat(s, "</p>\n");
47 }
48