mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
html_actor_icon() uses xs_html.
This commit is contained in:
parent
4fe2ccd670
commit
1ad4a93649
3 changed files with 73 additions and 55 deletions
78
html.c
78
html.c
|
@ -95,7 +95,7 @@ xs_str *actor_name(xs_dict *actor)
|
||||||
xs_str *html_actor_icon(xs_dict *actor, const char *date,
|
xs_str *html_actor_icon(xs_dict *actor, const char *date,
|
||||||
const char *udate, const char *url, int priv)
|
const char *udate, const char *url, int priv)
|
||||||
{
|
{
|
||||||
xs_str *s = xs_str_new(NULL);
|
xs_html *actor_icon = xs_html_tag("p", NULL);
|
||||||
|
|
||||||
xs *avatar = NULL;
|
xs *avatar = NULL;
|
||||||
char *v;
|
char *v;
|
||||||
|
@ -111,31 +111,45 @@ xs_str *html_actor_icon(xs_dict *actor, const char *date,
|
||||||
if (avatar == NULL)
|
if (avatar == NULL)
|
||||||
avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64());
|
avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64());
|
||||||
|
|
||||||
{
|
xs_html_add(actor_icon,
|
||||||
xs *s1 = xs_fmt("<p><img class=\"snac-avatar\" loading=\"lazy\" "
|
xs_html_sctag("img",
|
||||||
"src=\"%s\" alt=\"\"/>\n", avatar);
|
xs_html_attr("loading", "lazy"),
|
||||||
s = xs_str_cat(s, s1);
|
xs_html_attr("class", "snac-avatar"),
|
||||||
}
|
xs_html_attr("src", avatar),
|
||||||
|
xs_html_attr("alt", "")),
|
||||||
|
xs_html_tag("a",
|
||||||
|
xs_html_attr("href", xs_dict_get(actor, "id")),
|
||||||
|
xs_html_attr("class", "p-author h-card snac-author"),
|
||||||
|
xs_html_raw(name))); /* name is already html-escaped */
|
||||||
|
|
||||||
{
|
|
||||||
xs *s1 = xs_fmt("<a href=\"%s\" class=\"p-author h-card snac-author\">%s</a>",
|
|
||||||
xs_dict_get(actor, "id"), name);
|
|
||||||
s = xs_str_cat(s, s1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!xs_is_null(url)) {
|
if (!xs_is_null(url)) {
|
||||||
xs *s1 = xs_fmt(" <a href=\"%s\">»</a>", url);
|
xs_html_add(actor_icon,
|
||||||
s = xs_str_cat(s, s1);
|
xs_html_text(" "),
|
||||||
|
xs_html_tag("a",
|
||||||
|
xs_html_attr("href", (char *)url),
|
||||||
|
xs_html_text("»")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv)
|
if (priv) {
|
||||||
s = xs_str_cat(s, " <span title=\"private\">🔒</span>");
|
xs_html_add(actor_icon,
|
||||||
|
xs_html_text(" "),
|
||||||
|
xs_html_tag("span",
|
||||||
|
xs_html_attr("title", "private"),
|
||||||
|
xs_html_raw("🔒")));
|
||||||
|
}
|
||||||
|
|
||||||
if (strcmp(xs_dict_get(actor, "type"), "Service") == 0)
|
if (strcmp(xs_dict_get(actor, "type"), "Service") == 0) {
|
||||||
s = xs_str_cat(s, " <span title=\"bot\">🤖</span>");
|
xs_html_add(actor_icon,
|
||||||
|
xs_html_text(" "),
|
||||||
|
xs_html_tag("span",
|
||||||
|
xs_html_attr("title", "bot"),
|
||||||
|
xs_html_raw("🤖")));
|
||||||
|
}
|
||||||
|
|
||||||
if (xs_is_null(date)) {
|
if (xs_is_null(date)) {
|
||||||
s = xs_str_cat(s, "\n \n");
|
xs_html_add(actor_icon,
|
||||||
|
xs_html_raw(" "));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
xs *date_label = xs_crop_i(xs_dup(date), 0, 10);
|
xs *date_label = xs_crop_i(xs_dup(date), 0, 10);
|
||||||
|
@ -149,18 +163,16 @@ xs_str *html_actor_icon(xs_dict *actor, const char *date,
|
||||||
date_title = xs_str_cat(date_title, " / ", udate);
|
date_title = xs_str_cat(date_title, " / ", udate);
|
||||||
}
|
}
|
||||||
|
|
||||||
xs *edt = encode_html(date_title);
|
xs_html_add(actor_icon,
|
||||||
xs *edl = encode_html(date_label);
|
xs_html_text(" "),
|
||||||
xs *s1 = xs_fmt(
|
xs_html_tag("time",
|
||||||
"\n<time class=\"dt-published snac-pubdate\" title=\"%s\">%s</time>\n",
|
xs_html_attr("class", "dt-published snac-pubdate"),
|
||||||
edt, edl);
|
xs_html_attr("title", date_title),
|
||||||
|
xs_html_text(date_label)));
|
||||||
s = xs_str_cat(s, s1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
char *username, *id;
|
char *username, *id;
|
||||||
xs *s1;
|
|
||||||
|
|
||||||
if (xs_is_null(username = xs_dict_get(actor, "preferredUsername")) || *username == '\0') {
|
if (xs_is_null(username = xs_dict_get(actor, "preferredUsername")) || *username == '\0') {
|
||||||
/* This should never be reached */
|
/* This should never be reached */
|
||||||
|
@ -176,15 +188,15 @@ xs_str *html_actor_icon(xs_dict *actor, const char *date,
|
||||||
xs *domain = xs_split(id, "/");
|
xs *domain = xs_split(id, "/");
|
||||||
xs *user = xs_fmt("@%s@%s", username, xs_list_get(domain, 2));
|
xs *user = xs_fmt("@%s@%s", username, xs_list_get(domain, 2));
|
||||||
|
|
||||||
xs *u1 = encode_html(user);
|
xs_html_add(actor_icon,
|
||||||
s1 = xs_fmt(
|
xs_html_sctag("br", NULL),
|
||||||
"<br><a href=\"%s\" class=\"p-author-tag h-card snac-author-tag\">%s</a>",
|
xs_html_tag("a",
|
||||||
xs_dict_get(actor, "id"), u1);
|
xs_html_attr("href", xs_dict_get(actor, "id")),
|
||||||
|
xs_html_attr("class", "p-author-tag h-card snac-author-tag"),
|
||||||
s = xs_str_cat(s, s1);
|
xs_html_text(user)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return s;
|
return xs_html_render(actor_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
48
xs_html.h
48
xs_html.h
|
@ -12,12 +12,15 @@ xs_html *xs_html_attr(char *key, char *value);
|
||||||
xs_html *xs_html_text(char *content);
|
xs_html *xs_html_text(char *content);
|
||||||
xs_html *xs_html_raw(char *content);
|
xs_html *xs_html_raw(char *content);
|
||||||
|
|
||||||
xs_html *xs_html_add(xs_html *tag, xs_html *data);
|
xs_html *_xs_html_add(xs_html *tag, xs_html *var[]);
|
||||||
|
#define xs_html_add(tag, ...) _xs_html_add(tag, (xs_html *[]) { __VA_ARGS__, NULL })
|
||||||
|
|
||||||
xs_html *_xs_html_tag(char *tag, xs_html *var[]);
|
xs_html *_xs_html_tag(char *tag, xs_html *var[]);
|
||||||
#define xs_html_tag(tag, ...) _xs_html_tag(tag, (xs_html *[]) { __VA_ARGS__, NULL })
|
#define xs_html_tag(tag, ...) _xs_html_tag(tag, (xs_html *[]) { __VA_ARGS__, NULL })
|
||||||
|
|
||||||
xs_html *_xs_html_sctag(char *tag, xs_html *var[]);
|
xs_html *_xs_html_sctag(char *tag, xs_html *var[]);
|
||||||
#define xs_html_sctag(tag, ...) _xs_html_sctag(tag, (xs_html *[]) { __VA_ARGS__, NULL })
|
#define xs_html_sctag(tag, ...) _xs_html_sctag(tag, (xs_html *[]) { __VA_ARGS__, NULL })
|
||||||
|
|
||||||
xs_str *_xs_html_render(xs_html *h, xs_str *s);
|
xs_str *_xs_html_render(xs_html *h, xs_str *s);
|
||||||
#define xs_html_render(h) _xs_html_render(h, xs_str_new(NULL))
|
#define xs_html_render(h) _xs_html_render(h, xs_str_new(NULL))
|
||||||
|
|
||||||
|
@ -127,28 +130,32 @@ xs_html *xs_html_raw(char *content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xs_html *xs_html_add(xs_html *tag, xs_html *data)
|
xs_html *_xs_html_add(xs_html *tag, xs_html *var[])
|
||||||
/* add data (attrs, tags or text) to a tag */
|
/* add data (attrs, tags or text) to a tag */
|
||||||
{
|
{
|
||||||
xs_html **first;
|
while (*var) {
|
||||||
xs_html **last;
|
xs_html *data = *var++;
|
||||||
|
|
||||||
if (data->type == XS_HTML_ATTR) {
|
xs_html **first;
|
||||||
first = &tag->f_attr;
|
xs_html **last;
|
||||||
last = &tag->l_attr;
|
|
||||||
|
if (data->type == XS_HTML_ATTR) {
|
||||||
|
first = &tag->f_attr;
|
||||||
|
last = &tag->l_attr;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
first = &tag->f_tag;
|
||||||
|
last = &tag->l_tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*first == NULL)
|
||||||
|
*first = data;
|
||||||
|
|
||||||
|
if (*last != NULL)
|
||||||
|
(*last)->next = data;
|
||||||
|
|
||||||
|
*last = data;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
first = &tag->f_tag;
|
|
||||||
last = &tag->l_tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*first == NULL)
|
|
||||||
*first = data;
|
|
||||||
|
|
||||||
if (*last != NULL)
|
|
||||||
(*last)->next = data;
|
|
||||||
|
|
||||||
*last = data;
|
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
@ -162,8 +169,7 @@ static xs_html *_xs_html_tag_t(xs_html_type type, char *tag, xs_html *var[])
|
||||||
a->type = type;
|
a->type = type;
|
||||||
a->content = xs_dup(tag);
|
a->content = xs_dup(tag);
|
||||||
|
|
||||||
while (*var)
|
_xs_html_add(a, var);
|
||||||
xs_html_add(a, *var++);
|
|
||||||
|
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
/* 63beb583926bb5dfec89e1d694172cc887614460 2023-11-19T19:51:05+01:00 */
|
/* d9404322f5bad91811bc0ad13d63360b586919cc 2023-11-20T20:13:34+01:00 */
|
||||||
|
|
Loading…
Reference in a new issue