diff options
| author | 2023-11-28 11:45:20 +0100 | |
|---|---|---|
| committer | 2023-11-28 11:45:20 +0100 | |
| commit | e092a772b09a13abed6859a70f8ddc0e2b81f34e (patch) | |
| tree | 424e149462710cc5ca174018b74e3e5423e9d0a4 | |
| parent | Finally, html_people() is the first page totally managed by xs_html. (diff) | |
| download | snac2-e092a772b09a13abed6859a70f8ddc0e2b81f34e.tar.gz snac2-e092a772b09a13abed6859a70f8ddc0e2b81f34e.tar.xz snac2-e092a772b09a13abed6859a70f8ddc0e2b81f34e.zip | |
Attachments in html_entry() use now xs_html.
| -rw-r--r-- | html.c | 78 |
1 files changed, 53 insertions, 25 deletions
| @@ -1845,12 +1845,13 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 1845 | } | 1845 | } |
| 1846 | 1846 | ||
| 1847 | /* make custom css for attachments easier */ | 1847 | /* make custom css for attachments easier */ |
| 1848 | s = xs_str_cat(s, "<div class=\"snac-content-attachments\">\n"); | 1848 | xs_html *content_attachments = xs_html_tag("div", |
| 1849 | xs_html_attr("class", "snac-content-attachments")); | ||
| 1849 | 1850 | ||
| 1850 | xs_list *p = attach; | 1851 | xs_list *p = attach; |
| 1851 | 1852 | ||
| 1852 | while (xs_list_iter(&p, &v)) { | 1853 | while (xs_list_iter(&p, &v)) { |
| 1853 | const char *t = xs_dict_get(v, "mediaType"); | 1854 | char *t = xs_dict_get(v, "mediaType"); |
| 1854 | 1855 | ||
| 1855 | if (xs_is_null(t)) | 1856 | if (xs_is_null(t)) |
| 1856 | t = xs_dict_get(v, "type"); | 1857 | t = xs_dict_get(v, "type"); |
| @@ -1858,7 +1859,7 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 1858 | if (xs_is_null(t)) | 1859 | if (xs_is_null(t)) |
| 1859 | continue; | 1860 | continue; |
| 1860 | 1861 | ||
| 1861 | const char *url = xs_dict_get(v, "url"); | 1862 | char *url = xs_dict_get(v, "url"); |
| 1862 | if (xs_is_null(url)) | 1863 | if (xs_is_null(url)) |
| 1863 | url = xs_dict_get(v, "href"); | 1864 | url = xs_dict_get(v, "href"); |
| 1864 | if (xs_is_null(url)) | 1865 | if (xs_is_null(url)) |
| @@ -1866,53 +1867,80 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 1866 | 1867 | ||
| 1867 | /* infer MIME type from non-specific attachments */ | 1868 | /* infer MIME type from non-specific attachments */ |
| 1868 | if (xs_list_len(attach) < 2 && xs_match(t, "Link|Document")) { | 1869 | if (xs_list_len(attach) < 2 && xs_match(t, "Link|Document")) { |
| 1869 | const char *mt = xs_mime_by_ext(url); | 1870 | char *mt = (char *)xs_mime_by_ext(url); |
| 1870 | 1871 | ||
| 1871 | if (xs_match(mt, "image/*|audio/*|video/*")) /* */ | 1872 | if (xs_match(mt, "image/*|audio/*|video/*")) /* */ |
| 1872 | t = mt; | 1873 | t = mt; |
| 1873 | } | 1874 | } |
| 1874 | 1875 | ||
| 1875 | const char *name = xs_dict_get(v, "name"); | 1876 | char *name = xs_dict_get(v, "name"); |
| 1876 | if (xs_is_null(name)) | 1877 | if (xs_is_null(name)) |
| 1877 | name = xs_dict_get(msg, "name"); | 1878 | name = xs_dict_get(msg, "name"); |
| 1878 | if (xs_is_null(name)) | 1879 | if (xs_is_null(name)) |
| 1879 | name = L("No description"); | 1880 | name = L("No description"); |
| 1880 | 1881 | ||
| 1881 | xs *es1 = encode_html(name); | ||
| 1882 | xs *s1 = NULL; | ||
| 1883 | |||
| 1884 | if (xs_startswith(t, "image/") || strcmp(t, "Image") == 0) { | 1882 | if (xs_startswith(t, "image/") || strcmp(t, "Image") == 0) { |
| 1885 | s1 = xs_fmt( | 1883 | xs_html_add(content_attachments, |
| 1886 | "<a href=\"%s\" target=\"_blank\">" | 1884 | xs_html_tag("a", |
| 1887 | "<img loading=\"lazy\" src=\"%s\" alt=\"%s\" title=\"%s\"/></a>\n", | 1885 | xs_html_attr("href", url), |
| 1888 | url, url, es1, es1); | 1886 | xs_html_attr("target", "_blank"), |
| 1887 | xs_html_sctag("img", | ||
| 1888 | xs_html_attr("loading", "lazy"), | ||
| 1889 | xs_html_attr("src", url), | ||
| 1890 | xs_html_attr("alt", name), | ||
| 1891 | xs_html_attr("title", name)))); | ||
| 1889 | } | 1892 | } |
| 1890 | else | 1893 | else |
| 1891 | if (xs_startswith(t, "video/")) { | 1894 | if (xs_startswith(t, "video/")) { |
| 1892 | s1 = xs_fmt("<video style=\"width: 100%\" class=\"snac-embedded-video\" " | 1895 | xs_html_add(content_attachments, |
| 1893 | "controls src=\"%s\">Video: " | 1896 | xs_html_tag("video", |
| 1894 | "<a href=\"%s\">%s</a></video>\n", url, url, es1); | 1897 | xs_html_attr("style", "width: 100%"), |
| 1898 | xs_html_attr("class", "snac-embedded-video"), | ||
| 1899 | xs_html_attr("controls", NULL), | ||
| 1900 | xs_html_attr("src", url), | ||
| 1901 | xs_html_text(L("Video")), | ||
| 1902 | xs_html_text(": "), | ||
| 1903 | xs_html_tag("a", | ||
| 1904 | xs_html_attr("href", url), | ||
| 1905 | xs_html_text(name)))); | ||
| 1895 | } | 1906 | } |
| 1896 | else | 1907 | else |
| 1897 | if (xs_startswith(t, "audio/")) { | 1908 | if (xs_startswith(t, "audio/")) { |
| 1898 | s1 = xs_fmt("<audio style=\"width: 100%\" class=\"snac-embedded-audio\" " | 1909 | xs_html_add(content_attachments, |
| 1899 | "controls src=\"%s\">Audio: " | 1910 | xs_html_tag("audio", |
| 1900 | "<a href=\"%s\">%s</a></audio>\n", url, url, es1); | 1911 | xs_html_attr("style", "width: 100%"), |
| 1912 | xs_html_attr("class", "snac-embedded-audio"), | ||
| 1913 | xs_html_attr("controls", NULL), | ||
| 1914 | xs_html_attr("src", url), | ||
| 1915 | xs_html_text(L("Audio")), | ||
| 1916 | xs_html_text(": "), | ||
| 1917 | xs_html_tag("a", | ||
| 1918 | xs_html_attr("href", url), | ||
| 1919 | xs_html_text(name)))); | ||
| 1901 | } | 1920 | } |
| 1902 | else | 1921 | else |
| 1903 | if (strcmp(t, "Link") == 0) { | 1922 | if (strcmp(t, "Link") == 0) { |
| 1904 | xs *es2 = encode_html(url); | 1923 | xs_html_add(content_attachments, |
| 1905 | s1 = xs_fmt("<p><a href=\"%s\">%s</a></p>\n", url, es2); | 1924 | xs_html_tag("p", |
| 1925 | xs_html_tag("a", | ||
| 1926 | xs_html_attr("href", url), | ||
| 1927 | xs_html_text(url)))); | ||
| 1906 | } | 1928 | } |
| 1907 | else { | 1929 | else { |
| 1908 | s1 = xs_fmt("<p><a href=\"%s\">Attachment: %s</a></p>\n", url, es1); | 1930 | xs_html_add(content_attachments, |
| 1931 | xs_html_tag("p", | ||
| 1932 | xs_html_tag("a", | ||
| 1933 | xs_html_attr("href", url), | ||
| 1934 | xs_html_text(L("Attachment")), | ||
| 1935 | xs_html_text(": "), | ||
| 1936 | xs_html_text(url)))); | ||
| 1909 | } | 1937 | } |
| 1910 | |||
| 1911 | if (!xs_is_null(s1)) | ||
| 1912 | s = xs_str_cat(s, s1); | ||
| 1913 | } | 1938 | } |
| 1914 | 1939 | ||
| 1915 | s = xs_str_cat(s, "</div>\n"); | 1940 | { |
| 1941 | xs *s1 = xs_html_render(content_attachments); | ||
| 1942 | s = xs_str_cat(s, s1); | ||
| 1943 | } | ||
| 1916 | } | 1944 | } |
| 1917 | 1945 | ||
| 1918 | /* has this message an audience (i.e., comes from a channel or community)? */ | 1946 | /* has this message an audience (i.e., comes from a channel or community)? */ |