mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-22 05:15:04 +00:00
New function html_user_head().
This commit is contained in:
parent
de8c8c31f0
commit
a20e8b8cd5
1 changed files with 61 additions and 57 deletions
118
html.c
118
html.c
|
@ -380,28 +380,6 @@ xs_html *html_note(snac *user, char *summary,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static xs_str *html_base_header(xs_str *s)
|
|
||||||
{
|
|
||||||
xs_list *p;
|
|
||||||
xs_str *v;
|
|
||||||
|
|
||||||
s = xs_str_cat(s, "<!DOCTYPE html>\n<html>\n<head>\n");
|
|
||||||
s = xs_str_cat(s, "<meta name=\"viewport\" "
|
|
||||||
"content=\"width=device-width, initial-scale=1\"/>\n");
|
|
||||||
s = xs_str_cat(s, "<meta name=\"generator\" "
|
|
||||||
"content=\"" USER_AGENT "\"/>\n");
|
|
||||||
|
|
||||||
/* add server CSS */
|
|
||||||
p = xs_dict_get(srv_config, "cssurls");
|
|
||||||
while (xs_list_iter(&p, &v)) {
|
|
||||||
xs *s1 = xs_fmt("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"/>\n", v);
|
|
||||||
s = xs_str_cat(s, s1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static xs_html *html_base_head(void)
|
static xs_html *html_base_head(void)
|
||||||
{
|
{
|
||||||
xs_html *head = xs_html_tag("head",
|
xs_html *head = xs_html_tag("head",
|
||||||
|
@ -581,10 +559,9 @@ static xs_str *html_instance_header(xs_str *s, char *tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
xs_str *html_user_header(snac *snac, xs_str *s, int local)
|
xs_html *html_user_head(snac *user)
|
||||||
/* creates the HTML header */
|
|
||||||
{
|
{
|
||||||
s = html_base_header(s);
|
xs_html *head = html_base_head();
|
||||||
|
|
||||||
/* add the user CSS */
|
/* add the user CSS */
|
||||||
{
|
{
|
||||||
|
@ -592,7 +569,7 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local)
|
||||||
int size;
|
int size;
|
||||||
|
|
||||||
/* try to open the user css */
|
/* try to open the user css */
|
||||||
if (!valid_status(static_get(snac, "style.css", &css, &size, NULL, NULL))) {
|
if (!valid_status(static_get(user, "style.css", &css, &size, NULL, NULL))) {
|
||||||
/* it's not there; try to open the server-wide css */
|
/* it's not there; try to open the server-wide css */
|
||||||
FILE *f;
|
FILE *f;
|
||||||
xs *g_css_fn = xs_fmt("%s/style.css", srv_basedir);
|
xs *g_css_fn = xs_fmt("%s/style.css", srv_basedir);
|
||||||
|
@ -604,21 +581,21 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (css != NULL) {
|
if (css != NULL) {
|
||||||
xs *s1 = xs_fmt("<style>%s</style>\n", css);
|
xs_html_add(head,
|
||||||
s = xs_str_cat(s, s1);
|
xs_html_tag("style",
|
||||||
|
xs_html_text(css)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
/* title */
|
||||||
xs *es1 = encode_html(xs_dict_get(snac->config, "name"));
|
xs *title = xs_fmt("%s (@%s@%s)", xs_dict_get(user->config, "name"),
|
||||||
xs *es2 = encode_html(snac->uid);
|
user->uid, xs_dict_get(srv_config, "host"));
|
||||||
xs *es3 = encode_html(xs_dict_get(srv_config, "host"));
|
|
||||||
xs *s1 = xs_fmt("<title>%s (@%s@%s)</title>\n", es1, es2, es3);
|
|
||||||
|
|
||||||
s = xs_str_cat(s, s1);
|
xs_html_add(head,
|
||||||
}
|
xs_html_tag("title",
|
||||||
|
xs_html_text(title)));
|
||||||
|
|
||||||
xs *avatar = xs_dup(xs_dict_get(snac->config, "avatar"));
|
xs *avatar = xs_dup(xs_dict_get(user->config, "avatar"));
|
||||||
|
|
||||||
if (avatar == NULL || *avatar == '\0') {
|
if (avatar == NULL || *avatar == '\0') {
|
||||||
xs_free(avatar);
|
xs_free(avatar);
|
||||||
|
@ -626,7 +603,7 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
xs *s_bio = xs_dup(xs_dict_get(snac->config, "bio"));
|
xs *s_bio = xs_dup(xs_dict_get(user->config, "bio"));
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
/* shorten the bio */
|
/* shorten the bio */
|
||||||
|
@ -643,35 +620,62 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* og properties */
|
/* og properties */
|
||||||
xs *es1 = encode_html(xs_dict_get(srv_config, "host"));
|
xs_html_add(head,
|
||||||
xs *es2 = encode_html(xs_dict_get(snac->config, "name"));
|
xs_html_sctag("meta",
|
||||||
xs *es3 = encode_html(snac->uid);
|
xs_html_attr("property", "og:site_name"),
|
||||||
xs *es4 = encode_html(xs_dict_get(srv_config, "host"));
|
xs_html_attr("content", xs_dict_get(srv_config, "host"))),
|
||||||
xs *es5 = encode_html(s_bio);
|
xs_html_sctag("meta",
|
||||||
xs *es6 = encode_html(s_avatar);
|
xs_html_attr("property", "og:title"),
|
||||||
|
xs_html_attr("content", title)),
|
||||||
xs *s1 = xs_fmt(
|
xs_html_sctag("meta",
|
||||||
"<meta property=\"og:site_name\" content=\"%s\"/>\n"
|
xs_html_attr("property", "og:description"),
|
||||||
"<meta property=\"og:title\" content=\"%s (@%s@%s)\"/>\n"
|
xs_html_attr("content", s_bio)),
|
||||||
"<meta property=\"og:description\" content=\"%s\"/>\n"
|
xs_html_sctag("meta",
|
||||||
"<meta property=\"og:image\" content=\"%s\"/>\n"
|
xs_html_attr("property", "og:image"),
|
||||||
"<meta property=\"og:image:width\" content=\"300\"/>\n"
|
xs_html_attr("content", s_avatar)),
|
||||||
"<meta property=\"og:image:height\" content=\"300\"/>\n",
|
xs_html_sctag("meta",
|
||||||
es1, es2, es3, es4, es5, es6);
|
xs_html_attr("property", "og:width"),
|
||||||
s = xs_str_cat(s, s1);
|
xs_html_attr("content", "300")),
|
||||||
|
xs_html_sctag("meta",
|
||||||
|
xs_html_attr("property", "og:height"),
|
||||||
|
xs_html_attr("content", "300")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* RSS link */
|
||||||
|
xs *rss_url = xs_fmt("%s.rss", user->actor);
|
||||||
|
xs_html_add(head,
|
||||||
|
xs_html_sctag("link",
|
||||||
|
xs_html_attr("rel", "alternate"),
|
||||||
|
xs_html_attr("type", "application/rss+xml"),
|
||||||
|
xs_html_attr("title", "RSS"),
|
||||||
|
xs_html_attr("href", rss_url)));
|
||||||
|
|
||||||
|
return head;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
xs_str *html_user_header(snac *snac, xs_str *s, int local)
|
||||||
|
/* creates the HTML header */
|
||||||
|
{
|
||||||
|
xs_html *head = html_user_head(snac);
|
||||||
|
|
||||||
{
|
{
|
||||||
xs *s1 = xs_fmt("<link rel=\"alternate\" type=\"application/rss+xml\" "
|
xs *s1 = xs_html_render(head);
|
||||||
"title=\"RSS\" href=\"%s.rss\" />\n", snac->actor); /* snac->actor is likely need to be URLEncoded. */
|
s = xs_str_cat(s, "<!DOCTYPE html><html>\n", s1);
|
||||||
s = xs_str_cat(s, s1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s = xs_str_cat(s, "</head>\n<body>\n");
|
s = xs_str_cat(s, "\n<body>\n");
|
||||||
|
|
||||||
/* top nav */
|
/* top nav */
|
||||||
s = xs_str_cat(s, "<nav class=\"snac-top-nav\">");
|
s = xs_str_cat(s, "<nav class=\"snac-top-nav\">");
|
||||||
|
|
||||||
|
xs *avatar = xs_dup(xs_dict_get(snac->config, "avatar"));
|
||||||
|
|
||||||
|
if (avatar == NULL || *avatar == '\0') {
|
||||||
|
xs_free(avatar);
|
||||||
|
avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64());
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
xs *s1;
|
xs *s1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue