commit 814bfdc
default
·
2023-11-28 10:04:35 +0000 UTC
parent c963a29
New function html_user_body() (still unused).
1 files changed,
+163,
-3
M
html.c
M
html.c
+163,
-3
1@@ -434,7 +434,7 @@ xs_html *html_instance_head(void)
2 }
3
4
5-xs_html *html_instance_body(char *tag)
6+static xs_html *html_instance_body(char *tag)
7 {
8 char *host = xs_dict_get(srv_config, "host");
9 char *sdesc = xs_dict_get(srv_config, "short_description");
10@@ -655,8 +655,168 @@ xs_html *html_user_head(snac *user)
11 }
12
13
14-xs_str *html_user_header(snac *snac, xs_str *s, int local)
15-/* creates the HTML header */
16+static xs_html *html_user_body(snac *user, int local)
17+{
18+ xs_html *body = xs_html_tag("body", NULL);
19+
20+ /* top nav */
21+ xs_html *top_nav = xs_html_tag("nav",
22+ xs_html_attr("class", "snac-top-nav"));
23+
24+ xs *avatar = xs_dup(xs_dict_get(user->config, "avatar"));
25+
26+ if (avatar == NULL || *avatar == '\0') {
27+ xs_free(avatar);
28+ avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64());
29+ }
30+
31+ xs_html_add(top_nav,
32+ xs_html_sctag("img",
33+ xs_html_attr("src", avatar),
34+ xs_html_attr("class", "snac-avatar"),
35+ xs_html_attr("alt", "")));
36+
37+ if (local) {
38+ xs *rss_url = xs_fmt("%s.rss", user->actor);
39+ xs *admin_url = xs_fmt("%s/admin", user->actor);
40+
41+ xs_html_add(top_nav,
42+ xs_html_tag("a",
43+ xs_html_attr("href", rss_url),
44+ xs_html_text(L("RSS"))),
45+ xs_html_text(" - "),
46+ xs_html_tag("a",
47+ xs_html_attr("href", admin_url),
48+ xs_html_attr("rel", "nofollow"),
49+ xs_html_text(L("private"))));
50+ }
51+ else {
52+ xs *n_list = notify_list(user, 1);
53+ int n_len = xs_list_len(n_list);
54+ xs *n_str = NULL;
55+ xs_html *notify_count = NULL;
56+
57+ /* show the number of new notifications, if there are any */
58+ if (n_len) {
59+ xs *n_len_str = xs_fmt(" %d ", n_len);
60+ notify_count = xs_html_tag("sup",
61+ xs_html_attr("style", "background-color: red; color: white;"),
62+ xs_html_text(n_len_str));
63+ }
64+ else
65+ notify_count = xs_html_text("");
66+
67+ xs *admin_url = xs_fmt("%s/admin", user->actor);
68+ xs *notify_url = xs_fmt("%s/notifications", user->actor);
69+ xs *people_url = xs_fmt("%s/people", user->actor);
70+ xs_html_add(top_nav,
71+ xs_html_tag("a",
72+ xs_html_attr("href", user->actor),
73+ xs_html_text(L("public"))),
74+ xs_html_text(" - "),
75+ xs_html_tag("a",
76+ xs_html_attr("href", admin_url),
77+ xs_html_text(L("private"))),
78+ xs_html_text(" - "),
79+ xs_html_tag("a",
80+ xs_html_attr("href", notify_url),
81+ xs_html_text(L("notifications"))),
82+ notify_count,
83+ xs_html_text(" - "),
84+ xs_html_tag("a",
85+ xs_html_attr("href", people_url),
86+ xs_html_text(L("people"))));
87+ }
88+
89+ xs_html_add(body,
90+ top_nav);
91+
92+ /* user info */
93+ xs_html *top_user = xs_html_tag("div",
94+ xs_html_attr("class", "h-card snac-top-user"));
95+
96+ if (local) {
97+ char *header = xs_dict_get(user->config, "header");
98+ if (header && *header) {
99+ xs_html_add(top_user,
100+ xs_html_tag("div",
101+ xs_html_attr("class", "snac-top-user-banner"),
102+ xs_html_attr("style", "clear: both"),
103+ xs_html_sctag("br", NULL),
104+ xs_html_sctag("img",
105+ xs_html_attr("src", header))));
106+ }
107+ }
108+
109+ xs *handle = xs_fmt("@%s@%s",
110+ xs_dict_get(user->config, "uid"),
111+ xs_dict_get(srv_config, "host"));
112+
113+ xs_html_add(top_user,
114+ xs_html_tag("p",
115+ xs_html_attr("class", "p-name snac-top-user-name"),
116+ xs_html_text(xs_dict_get(user->config, "name"))),
117+ xs_html_tag("p",
118+ xs_html_attr("class", "snac-top-user-id"),
119+ xs_html_text(handle)));
120+
121+ if (local) {
122+ xs *es1 = encode_html(xs_dict_get(user->config, "bio"));
123+ xs *bio1 = not_really_markdown(es1, NULL);
124+ xs *tags = xs_list_new();
125+ xs *bio2 = process_tags(user, bio1, &tags);
126+
127+ xs_html *top_user_bio = xs_html_tag("div",
128+ xs_html_attr("class", "p-note snac-top-user-bio"),
129+ xs_html_raw(bio2)); /* already sanitized */
130+
131+ xs_html_add(top_user,
132+ top_user_bio);
133+
134+ xs_dict *metadata = xs_dict_get(user->config, "metadata");
135+ if (xs_type(metadata) == XSTYPE_DICT) {
136+ xs_str *k;
137+ xs_str *v;
138+
139+ xs_html *snac_metadata = xs_html_tag("div",
140+ xs_html_attr("class", "snac-metadata"));
141+
142+ while (xs_dict_iter(&metadata, &k, &v)) {
143+ xs_html *value;
144+
145+ if (xs_startswith(v, "https:/" "/"))
146+ value = xs_html_tag("a",
147+ xs_html_attr("href", v),
148+ xs_html_text(v));
149+ else
150+ value = xs_html_text(v);
151+
152+ xs_html_add(snac_metadata,
153+ xs_html_tag("span",
154+ xs_html_attr("class", "snac-property-name"),
155+ xs_html_text(k)),
156+ xs_html_text(":"),
157+ xs_html_sctag("br", NULL),
158+ xs_html_tag("span",
159+ xs_html_attr("class", "snac-property-value"),
160+ value),
161+ xs_html_sctag("br", NULL));
162+ }
163+
164+ xs_html_add(top_user,
165+ snac_metadata);
166+ }
167+ }
168+
169+ xs_html_add(body,
170+ top_user);
171+
172+ return body;
173+}
174+
175+
176+static xs_str *html_user_header(snac *snac, xs_str *s, int local)
177+/* TO BE REPLACED BY html_user_body() */
178 {
179 xs_html *head = html_user_head(snac);
180