diff options
| author | 2023-11-29 10:17:41 +0100 | |
|---|---|---|
| committer | 2023-11-29 10:17:41 +0100 | |
| commit | 9419b808094c5a9dbb134b9aaaee7303b8af188d (patch) | |
| tree | c5f355f82678112f35fccd7af4ef04feec29dc41 | |
| parent | html_timeline() now uses xs_html. (diff) | |
| download | snac2-9419b808094c5a9dbb134b9aaaee7303b8af188d.tar.gz snac2-9419b808094c5a9dbb134b9aaaee7303b8af188d.tar.xz snac2-9419b808094c5a9dbb134b9aaaee7303b8af188d.zip | |
Got rid of dead code.
| -rw-r--r-- | html.c | 246 |
1 files changed, 6 insertions, 240 deletions
| @@ -80,7 +80,8 @@ xs_str *actor_name(xs_dict *actor) | |||
| 80 | 80 | ||
| 81 | if (n && i) { | 81 | if (n && i) { |
| 82 | char *u = xs_dict_get(i, "url"); | 82 | char *u = xs_dict_get(i, "url"); |
| 83 | xs *img = xs_fmt("<img loading=\"lazy\" src=\"%s\" style=\"height: 1em; vertical-align: middle;\"/>", u); | 83 | xs *img = xs_fmt("<img loading=\"lazy\" src=\"%s\" " |
| 84 | "style=\"height: 1em; vertical-align: middle;\"/>", u); | ||
| 84 | 85 | ||
| 85 | name = xs_replace_i(name, n, img); | 86 | name = xs_replace_i(name, n, img); |
| 86 | } | 87 | } |
| @@ -499,67 +500,6 @@ static xs_html *html_instance_body(char *tag) | |||
| 499 | } | 500 | } |
| 500 | 501 | ||
| 501 | 502 | ||
| 502 | static xs_str *html_instance_header(xs_str *s, char *tag) | ||
| 503 | /* TO BE REPLACED BY html_instance_body() */ | ||
| 504 | { | ||
| 505 | xs_html *head = html_instance_head(); | ||
| 506 | |||
| 507 | char *host = xs_dict_get(srv_config, "host"); | ||
| 508 | char *sdesc = xs_dict_get(srv_config, "short_description"); | ||
| 509 | char *email = xs_dict_get(srv_config, "admin_email"); | ||
| 510 | char *acct = xs_dict_get(srv_config, "admin_account"); | ||
| 511 | |||
| 512 | { | ||
| 513 | xs *s1 = xs_html_render(head); | ||
| 514 | s = xs_str_cat(s, "<!DOCTYPE html><html>\n", s1); | ||
| 515 | } | ||
| 516 | |||
| 517 | s = xs_str_cat(s, "<body>\n"); | ||
| 518 | |||
| 519 | s = xs_str_cat(s, "<div class=\"snac-instance-blurb\">\n"); | ||
| 520 | |||
| 521 | { | ||
| 522 | xs *s1 = xs_replace(snac_blurb, "%host%", host); | ||
| 523 | s = xs_str_cat(s, s1); | ||
| 524 | } | ||
| 525 | |||
| 526 | s = xs_str_cat(s, "<dl>\n"); | ||
| 527 | |||
| 528 | if (sdesc && *sdesc) { | ||
| 529 | xs *s1 = xs_fmt("<di><dt>%s</dt><dd>%s</dd></di>\n", L("Site description"), sdesc); | ||
| 530 | s = xs_str_cat(s, s1); | ||
| 531 | } | ||
| 532 | if (email && *email) { | ||
| 533 | xs *s1 = xs_fmt("<di><dt>%s</dt><dd>" | ||
| 534 | "<a href=\"mailto:%s\">%s</a></dd></di>\n", | ||
| 535 | L("Admin email"), email, email); | ||
| 536 | |||
| 537 | s = xs_str_cat(s, s1); | ||
| 538 | } | ||
| 539 | if (acct && *acct) { | ||
| 540 | xs *s1 = xs_fmt("<di><dt>%s</dt><dd>" | ||
| 541 | "<a href=\"%s/%s\">@%s@%s</a></dd></di>\n", | ||
| 542 | L("Admin account"), srv_baseurl, acct, acct, host); | ||
| 543 | |||
| 544 | s = xs_str_cat(s, s1); | ||
| 545 | } | ||
| 546 | |||
| 547 | s = xs_str_cat(s, "</dl>\n"); | ||
| 548 | |||
| 549 | s = xs_str_cat(s, "</div>\n"); | ||
| 550 | |||
| 551 | { | ||
| 552 | xs *l = tag ? xs_fmt(L("Search results for #%s"), tag) : | ||
| 553 | xs_dup(L("Recent posts by users in this instance")); | ||
| 554 | |||
| 555 | xs *s1 = xs_fmt("<h2 class=\"snac-header\">%s</h2>\n", l); | ||
| 556 | s = xs_str_cat(s, s1); | ||
| 557 | } | ||
| 558 | |||
| 559 | return s; | ||
| 560 | } | ||
| 561 | |||
| 562 | |||
| 563 | xs_html *html_user_head(snac *user) | 503 | xs_html *html_user_head(snac *user) |
| 564 | { | 504 | { |
| 565 | xs_html *head = html_base_head(); | 505 | xs_html *head = html_base_head(); |
| @@ -815,182 +755,6 @@ static xs_html *html_user_body(snac *user, int local) | |||
| 815 | } | 755 | } |
| 816 | 756 | ||
| 817 | 757 | ||
| 818 | static xs_str *html_user_header(snac *snac, xs_str *s, int local) | ||
| 819 | /* TO BE REPLACED BY html_user_body() */ | ||
| 820 | { | ||
| 821 | xs_html *head = html_user_head(snac); | ||
| 822 | |||
| 823 | { | ||
| 824 | xs *s1 = xs_html_render(head); | ||
| 825 | s = xs_str_cat(s, "<!DOCTYPE html><html>\n", s1); | ||
| 826 | } | ||
| 827 | |||
| 828 | s = xs_str_cat(s, "\n<body>\n"); | ||
| 829 | |||
| 830 | /* top nav */ | ||
| 831 | xs_html *top_nav = xs_html_tag("nav", | ||
| 832 | xs_html_attr("class", "snac-top-nav")); | ||
| 833 | |||
| 834 | xs *avatar = xs_dup(xs_dict_get(snac->config, "avatar")); | ||
| 835 | |||
| 836 | if (avatar == NULL || *avatar == '\0') { | ||
| 837 | xs_free(avatar); | ||
| 838 | avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64()); | ||
| 839 | } | ||
| 840 | |||
| 841 | xs_html_add(top_nav, | ||
| 842 | xs_html_sctag("img", | ||
| 843 | xs_html_attr("src", avatar), | ||
| 844 | xs_html_attr("class", "snac-avatar"), | ||
| 845 | xs_html_attr("alt", ""))); | ||
| 846 | |||
| 847 | { | ||
| 848 | if (local) { | ||
| 849 | xs *rss_url = xs_fmt("%s.rss", snac->actor); | ||
| 850 | xs *admin_url = xs_fmt("%s/admin", snac->actor); | ||
| 851 | |||
| 852 | xs_html_add(top_nav, | ||
| 853 | xs_html_tag("a", | ||
| 854 | xs_html_attr("href", rss_url), | ||
| 855 | xs_html_text(L("RSS"))), | ||
| 856 | xs_html_text(" - "), | ||
| 857 | xs_html_tag("a", | ||
| 858 | xs_html_attr("href", admin_url), | ||
| 859 | xs_html_attr("rel", "nofollow"), | ||
| 860 | xs_html_text(L("private")))); | ||
| 861 | } | ||
| 862 | else { | ||
| 863 | xs *n_list = notify_list(snac, 1); | ||
| 864 | int n_len = xs_list_len(n_list); | ||
| 865 | xs *n_str = NULL; | ||
| 866 | xs_html *notify_count = NULL; | ||
| 867 | |||
| 868 | /* show the number of new notifications, if there are any */ | ||
| 869 | if (n_len) { | ||
| 870 | xs *n_len_str = xs_fmt(" %d ", n_len); | ||
| 871 | notify_count = xs_html_tag("sup", | ||
| 872 | xs_html_attr("style", "background-color: red; color: white;"), | ||
| 873 | xs_html_text(n_len_str)); | ||
| 874 | } | ||
| 875 | else | ||
| 876 | notify_count = xs_html_text(""); | ||
| 877 | |||
| 878 | xs *admin_url = xs_fmt("%s/admin", snac->actor); | ||
| 879 | xs *notify_url = xs_fmt("%s/notifications", snac->actor); | ||
| 880 | xs *people_url = xs_fmt("%s/people", snac->actor); | ||
| 881 | xs_html_add(top_nav, | ||
| 882 | xs_html_tag("a", | ||
| 883 | xs_html_attr("href", snac->actor), | ||
| 884 | xs_html_text(L("public"))), | ||
| 885 | xs_html_text(" - "), | ||
| 886 | xs_html_tag("a", | ||
| 887 | xs_html_attr("href", admin_url), | ||
| 888 | xs_html_text(L("private"))), | ||
| 889 | xs_html_text(" - "), | ||
| 890 | xs_html_tag("a", | ||
| 891 | xs_html_attr("href", notify_url), | ||
| 892 | xs_html_text(L("notifications"))), | ||
| 893 | notify_count, | ||
| 894 | xs_html_text(" - "), | ||
| 895 | xs_html_tag("a", | ||
| 896 | xs_html_attr("href", people_url), | ||
| 897 | xs_html_text(L("people")))); | ||
| 898 | } | ||
| 899 | } | ||
| 900 | |||
| 901 | { | ||
| 902 | xs *s1 = xs_html_render(top_nav); | ||
| 903 | s = xs_str_cat(s, s1); | ||
| 904 | } | ||
| 905 | |||
| 906 | /* user info */ | ||
| 907 | { | ||
| 908 | xs_html *top_user = xs_html_tag("div", | ||
| 909 | xs_html_attr("class", "h-card snac-top-user")); | ||
| 910 | |||
| 911 | if (local) { | ||
| 912 | char *header = xs_dict_get(snac->config, "header"); | ||
| 913 | if (header && *header) { | ||
| 914 | xs_html_add(top_user, | ||
| 915 | xs_html_tag("div", | ||
| 916 | xs_html_attr("class", "snac-top-user-banner"), | ||
| 917 | xs_html_attr("style", "clear: both"), | ||
| 918 | xs_html_sctag("br", NULL), | ||
| 919 | xs_html_sctag("img", | ||
| 920 | xs_html_attr("src", header)))); | ||
| 921 | } | ||
| 922 | } | ||
| 923 | |||
| 924 | xs *handle = xs_fmt("@%s@%s", | ||
| 925 | xs_dict_get(snac->config, "uid"), | ||
| 926 | xs_dict_get(srv_config, "host")); | ||
| 927 | |||
| 928 | xs_html_add(top_user, | ||
| 929 | xs_html_tag("p", | ||
| 930 | xs_html_attr("class", "p-name snac-top-user-name"), | ||
| 931 | xs_html_text(xs_dict_get(snac->config, "name"))), | ||
| 932 | xs_html_tag("p", | ||
| 933 | xs_html_attr("class", "snac-top-user-id"), | ||
| 934 | xs_html_text(handle))); | ||
| 935 | |||
| 936 | if (local) { | ||
| 937 | xs *es1 = encode_html(xs_dict_get(snac->config, "bio")); | ||
| 938 | xs *bio1 = not_really_markdown(es1, NULL); | ||
| 939 | xs *tags = xs_list_new(); | ||
| 940 | xs *bio2 = process_tags(snac, bio1, &tags); | ||
| 941 | |||
| 942 | xs_html *top_user_bio = xs_html_tag("div", | ||
| 943 | xs_html_attr("class", "p-note snac-top-user-bio"), | ||
| 944 | xs_html_raw(bio2)); /* already sanitized */ | ||
| 945 | |||
| 946 | xs_html_add(top_user, | ||
| 947 | top_user_bio); | ||
| 948 | |||
| 949 | xs_dict *metadata = xs_dict_get(snac->config, "metadata"); | ||
| 950 | if (xs_type(metadata) == XSTYPE_DICT) { | ||
| 951 | xs_str *k; | ||
| 952 | xs_str *v; | ||
| 953 | |||
| 954 | xs_html *snac_metadata = xs_html_tag("div", | ||
| 955 | xs_html_attr("class", "snac-metadata")); | ||
| 956 | |||
| 957 | while (xs_dict_iter(&metadata, &k, &v)) { | ||
| 958 | xs_html *value; | ||
| 959 | |||
| 960 | if (xs_startswith(v, "https:/" "/")) | ||
| 961 | value = xs_html_tag("a", | ||
| 962 | xs_html_attr("href", v), | ||
| 963 | xs_html_text(v)); | ||
| 964 | else | ||
| 965 | value = xs_html_text(v); | ||
| 966 | |||
| 967 | xs_html_add(snac_metadata, | ||
| 968 | xs_html_tag("span", | ||
| 969 | xs_html_attr("class", "snac-property-name"), | ||
| 970 | xs_html_text(k)), | ||
| 971 | xs_html_text(":"), | ||
| 972 | xs_html_sctag("br", NULL), | ||
| 973 | xs_html_tag("span", | ||
| 974 | xs_html_attr("class", "snac-property-value"), | ||
| 975 | value), | ||
| 976 | xs_html_sctag("br", NULL)); | ||
| 977 | } | ||
| 978 | |||
| 979 | xs_html_add(top_user, | ||
| 980 | snac_metadata); | ||
| 981 | } | ||
| 982 | } | ||
| 983 | |||
| 984 | { | ||
| 985 | xs *s1 = xs_html_render(top_user); | ||
| 986 | s = xs_str_cat(s, s1); | ||
| 987 | } | ||
| 988 | } | ||
| 989 | |||
| 990 | return s; | ||
| 991 | } | ||
| 992 | |||
| 993 | |||
| 994 | xs_html *html_top_controls(snac *snac) | 758 | xs_html *html_top_controls(snac *snac) |
| 995 | /* generates the top controls */ | 759 | /* generates the top controls */ |
| 996 | { | 760 | { |
| @@ -1196,7 +960,8 @@ xs_html *html_top_controls(snac *snac) | |||
| 1196 | xs_html_attr(xs_type(a_private) == XSTYPE_TRUE ? "checked" : "", NULL)), | 960 | xs_html_attr(xs_type(a_private) == XSTYPE_TRUE ? "checked" : "", NULL)), |
| 1197 | xs_html_tag("label", | 961 | xs_html_tag("label", |
| 1198 | xs_html_attr("for", "private"), | 962 | xs_html_attr("for", "private"), |
| 1199 | xs_html_text(L("This account is private (posts are not shown through the web)")))), | 963 | xs_html_text(L("This account is private " |
| 964 | "(posts are not shown through the web)")))), | ||
| 1200 | xs_html_tag("p", | 965 | xs_html_tag("p", |
| 1201 | xs_html_text(L("Profile metadata (key=value pairs in each line):")), | 966 | xs_html_text(L("Profile metadata (key=value pairs in each line):")), |
| 1202 | xs_html_sctag("br", NULL), | 967 | xs_html_sctag("br", NULL), |
| @@ -1204,7 +969,8 @@ xs_html *html_top_controls(snac *snac) | |||
| 1204 | xs_html_attr("name", "metadata"), | 969 | xs_html_attr("name", "metadata"), |
| 1205 | xs_html_attr("cols", "40"), | 970 | xs_html_attr("cols", "40"), |
| 1206 | xs_html_attr("rows", "4"), | 971 | xs_html_attr("rows", "4"), |
| 1207 | xs_html_attr("placeholder", "Blog=https:/" "/example.com/my-blog\nGPG Key=1FA54\n..."), | 972 | xs_html_attr("placeholder", "Blog=https:/" |
| 973 | "/example.com/my-blog\nGPG Key=1FA54\n..."), | ||
| 1208 | xs_html_text(metadata))), | 974 | xs_html_text(metadata))), |
| 1209 | 975 | ||
| 1210 | xs_html_tag("p", | 976 | xs_html_tag("p", |