commit 6878e3f

grunfink  ·  2025-05-03 16:55:10 +0000 UTC
parent 136b7c1
Also add direct and markdown links in posts as attachments.
2 files changed,  +26, -3
M html.c
+25, -2
 1@@ -154,10 +154,22 @@ static xs_str *format_line(const char *line, xs_list **attach)
 2                 xs *l = xs_split_n(w, "](", 1);
 3 
 4                 if (xs_list_len(l) == 2) {
 5-                    xs *link = xs_fmt("<a href=\"%s\">%s</a>",
 6-                            xs_list_get(l, 1), xs_list_get(l, 0));
 7+                    const char *name = xs_list_get(l, 0);
 8+                    const char *url  = xs_list_get(l, 1);
 9+
10+                    xs *link = xs_fmt("<a href=\"%s\">%s</a>", url, name);
11 
12                     s = xs_str_cat(s, link);
13+
14+                    /* also add the link as an attachment */
15+                    xs *d = xs_dict_new();
16+
17+                    d = xs_dict_append(d, "mediaType", "text/html");
18+                    d = xs_dict_append(d, "url",       url);
19+                    d = xs_dict_append(d, "name",      name);
20+                    d = xs_dict_append(d, "type",      "Link");
21+
22+                    *attach = xs_list_append(*attach, d);
23                 }
24                 else
25                     s = xs_str_cat(s, v);
26@@ -208,6 +220,7 @@ static xs_str *format_line(const char *line, xs_list **attach)
27             }
28             else
29             if (xs_str_in(v, ":/" "/") != -1) {
30+                /* direct URLs in the post body */
31                 xs *u  = xs_replace_i(xs_replace(v, "#", "&#35;"), "@", "&#64;");
32 
33                 xs *v2 = xs_strip_chars_i(xs_dup(u), ".,)");
34@@ -240,6 +253,16 @@ static xs_str *format_line(const char *line, xs_list **attach)
35                 else {
36                     xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);
37                     s = xs_str_cat(s, s1);
38+
39+                    /* also add the link as an attachment */
40+                    xs *d = xs_dict_new();
41+
42+                    d = xs_dict_append(d, "mediaType", "text/html");
43+                    d = xs_dict_append(d, "url",       v2);
44+                    d = xs_dict_append(d, "name",      "");
45+                    d = xs_dict_append(d, "type",      "Link");
46+
47+                    *attach = xs_list_append(*attach, d);
48                 }
49             }
50             else
M html.c
+1, -1
1@@ -2388,7 +2388,7 @@ xs_html *html_entry(snac *user, xs_dict *msg, int read_only,
2             const char *o_href = xs_dict_get(a, "href");
3             const char *name = xs_dict_get(a, "name");
4 
5-            /* if this image is already in the post content, skip */
6+            /* if this URL is already in the post content, skip */
7             if (content && xs_str_in(content, o_href) != -1)
8                 continue;
9