diff options
| author | 2023-11-27 21:06:04 +0100 | |
|---|---|---|
| committer | 2023-11-27 21:06:04 +0100 | |
| commit | a20e8b8cd5c15e5e89696540d306e5f0bab4f174 (patch) | |
| tree | 4674b00383259bbbd0d3c38107224dc14a648fe0 | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | snac2-a20e8b8cd5c15e5e89696540d306e5f0bab4f174.tar.gz snac2-a20e8b8cd5c15e5e89696540d306e5f0bab4f174.tar.xz snac2-a20e8b8cd5c15e5e89696540d306e5f0bab4f174.zip | |
New function html_user_head().
| -rw-r--r-- | html.c | 118 |
1 files changed, 61 insertions, 57 deletions
| @@ -380,28 +380,6 @@ xs_html *html_note(snac *user, char *summary, | |||
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | 382 | ||
| 383 | static xs_str *html_base_header(xs_str *s) | ||
| 384 | { | ||
| 385 | xs_list *p; | ||
| 386 | xs_str *v; | ||
| 387 | |||
| 388 | s = xs_str_cat(s, "<!DOCTYPE html>\n<html>\n<head>\n"); | ||
| 389 | s = xs_str_cat(s, "<meta name=\"viewport\" " | ||
| 390 | "content=\"width=device-width, initial-scale=1\"/>\n"); | ||
| 391 | s = xs_str_cat(s, "<meta name=\"generator\" " | ||
| 392 | "content=\"" USER_AGENT "\"/>\n"); | ||
| 393 | |||
| 394 | /* add server CSS */ | ||
| 395 | p = xs_dict_get(srv_config, "cssurls"); | ||
| 396 | while (xs_list_iter(&p, &v)) { | ||
| 397 | xs *s1 = xs_fmt("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"/>\n", v); | ||
| 398 | s = xs_str_cat(s, s1); | ||
| 399 | } | ||
| 400 | |||
| 401 | return s; | ||
| 402 | } | ||
| 403 | |||
| 404 | |||
| 405 | static xs_html *html_base_head(void) | 383 | static xs_html *html_base_head(void) |
| 406 | { | 384 | { |
| 407 | xs_html *head = xs_html_tag("head", | 385 | xs_html *head = xs_html_tag("head", |
| @@ -581,10 +559,9 @@ static xs_str *html_instance_header(xs_str *s, char *tag) | |||
| 581 | } | 559 | } |
| 582 | 560 | ||
| 583 | 561 | ||
| 584 | xs_str *html_user_header(snac *snac, xs_str *s, int local) | 562 | xs_html *html_user_head(snac *user) |
| 585 | /* creates the HTML header */ | ||
| 586 | { | 563 | { |
| 587 | s = html_base_header(s); | 564 | xs_html *head = html_base_head(); |
| 588 | 565 | ||
| 589 | /* add the user CSS */ | 566 | /* add the user CSS */ |
| 590 | { | 567 | { |
| @@ -592,7 +569,7 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local) | |||
| 592 | int size; | 569 | int size; |
| 593 | 570 | ||
| 594 | /* try to open the user css */ | 571 | /* try to open the user css */ |
| 595 | if (!valid_status(static_get(snac, "style.css", &css, &size, NULL, NULL))) { | 572 | if (!valid_status(static_get(user, "style.css", &css, &size, NULL, NULL))) { |
| 596 | /* it's not there; try to open the server-wide css */ | 573 | /* it's not there; try to open the server-wide css */ |
| 597 | FILE *f; | 574 | FILE *f; |
| 598 | xs *g_css_fn = xs_fmt("%s/style.css", srv_basedir); | 575 | 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) | |||
| 604 | } | 581 | } |
| 605 | 582 | ||
| 606 | if (css != NULL) { | 583 | if (css != NULL) { |
| 607 | xs *s1 = xs_fmt("<style>%s</style>\n", css); | 584 | xs_html_add(head, |
| 608 | s = xs_str_cat(s, s1); | 585 | xs_html_tag("style", |
| 586 | xs_html_text(css))); | ||
| 609 | } | 587 | } |
| 610 | } | 588 | } |
| 611 | 589 | ||
| 612 | { | 590 | /* title */ |
| 613 | xs *es1 = encode_html(xs_dict_get(snac->config, "name")); | 591 | xs *title = xs_fmt("%s (@%s@%s)", xs_dict_get(user->config, "name"), |
| 614 | xs *es2 = encode_html(snac->uid); | 592 | user->uid, xs_dict_get(srv_config, "host")); |
| 615 | xs *es3 = encode_html(xs_dict_get(srv_config, "host")); | ||
| 616 | xs *s1 = xs_fmt("<title>%s (@%s@%s)</title>\n", es1, es2, es3); | ||
| 617 | 593 | ||
| 618 | s = xs_str_cat(s, s1); | 594 | xs_html_add(head, |
| 619 | } | 595 | xs_html_tag("title", |
| 596 | xs_html_text(title))); | ||
| 620 | 597 | ||
| 621 | xs *avatar = xs_dup(xs_dict_get(snac->config, "avatar")); | 598 | xs *avatar = xs_dup(xs_dict_get(user->config, "avatar")); |
| 622 | 599 | ||
| 623 | if (avatar == NULL || *avatar == '\0') { | 600 | if (avatar == NULL || *avatar == '\0') { |
| 624 | xs_free(avatar); | 601 | xs_free(avatar); |
| @@ -626,7 +603,7 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local) | |||
| 626 | } | 603 | } |
| 627 | 604 | ||
| 628 | { | 605 | { |
| 629 | xs *s_bio = xs_dup(xs_dict_get(snac->config, "bio")); | 606 | xs *s_bio = xs_dup(xs_dict_get(user->config, "bio")); |
| 630 | int n; | 607 | int n; |
| 631 | 608 | ||
| 632 | /* shorten the bio */ | 609 | /* shorten the bio */ |
| @@ -643,35 +620,62 @@ xs_str *html_user_header(snac *snac, xs_str *s, int local) | |||
| 643 | } | 620 | } |
| 644 | 621 | ||
| 645 | /* og properties */ | 622 | /* og properties */ |
| 646 | xs *es1 = encode_html(xs_dict_get(srv_config, "host")); | 623 | xs_html_add(head, |
| 647 | xs *es2 = encode_html(xs_dict_get(snac->config, "name")); | 624 | xs_html_sctag("meta", |
| 648 | xs *es3 = encode_html(snac->uid); | 625 | xs_html_attr("property", "og:site_name"), |
| 649 | xs *es4 = encode_html(xs_dict_get(srv_config, "host")); | 626 | xs_html_attr("content", xs_dict_get(srv_config, "host"))), |
| 650 | xs *es5 = encode_html(s_bio); | 627 | xs_html_sctag("meta", |
| 651 | xs *es6 = encode_html(s_avatar); | 628 | xs_html_attr("property", "og:title"), |
| 629 | xs_html_attr("content", title)), | ||
| 630 | xs_html_sctag("meta", | ||
| 631 | xs_html_attr("property", "og:description"), | ||
| 632 | xs_html_attr("content", s_bio)), | ||
| 633 | xs_html_sctag("meta", | ||
| 634 | xs_html_attr("property", "og:image"), | ||
| 635 | xs_html_attr("content", s_avatar)), | ||
| 636 | xs_html_sctag("meta", | ||
| 637 | xs_html_attr("property", "og:width"), | ||
| 638 | xs_html_attr("content", "300")), | ||
| 639 | xs_html_sctag("meta", | ||
| 640 | xs_html_attr("property", "og:height"), | ||
| 641 | xs_html_attr("content", "300"))); | ||
| 642 | } | ||
| 643 | |||
| 644 | /* RSS link */ | ||
| 645 | xs *rss_url = xs_fmt("%s.rss", user->actor); | ||
| 646 | xs_html_add(head, | ||
| 647 | xs_html_sctag("link", | ||
| 648 | xs_html_attr("rel", "alternate"), | ||
| 649 | xs_html_attr("type", "application/rss+xml"), | ||
| 650 | xs_html_attr("title", "RSS"), | ||
| 651 | xs_html_attr("href", rss_url))); | ||
| 652 | 652 | ||
| 653 | xs *s1 = xs_fmt( | 653 | return head; |
| 654 | "<meta property=\"og:site_name\" content=\"%s\"/>\n" | 654 | } |
| 655 | "<meta property=\"og:title\" content=\"%s (@%s@%s)\"/>\n" | 655 | |
| 656 | "<meta property=\"og:description\" content=\"%s\"/>\n" | 656 | |
| 657 | "<meta property=\"og:image\" content=\"%s\"/>\n" | 657 | xs_str *html_user_header(snac *snac, xs_str *s, int local) |
| 658 | "<meta property=\"og:image:width\" content=\"300\"/>\n" | 658 | /* creates the HTML header */ |
| 659 | "<meta property=\"og:image:height\" content=\"300\"/>\n", | 659 | { |
| 660 | es1, es2, es3, es4, es5, es6); | 660 | xs_html *head = html_user_head(snac); |
| 661 | s = xs_str_cat(s, s1); | ||
| 662 | } | ||
| 663 | 661 | ||
| 664 | { | 662 | { |
| 665 | xs *s1 = xs_fmt("<link rel=\"alternate\" type=\"application/rss+xml\" " | 663 | xs *s1 = xs_html_render(head); |
| 666 | "title=\"RSS\" href=\"%s.rss\" />\n", snac->actor); /* snac->actor is likely need to be URLEncoded. */ | 664 | s = xs_str_cat(s, "<!DOCTYPE html><html>\n", s1); |
| 667 | s = xs_str_cat(s, s1); | ||
| 668 | } | 665 | } |
| 669 | 666 | ||
| 670 | s = xs_str_cat(s, "</head>\n<body>\n"); | 667 | s = xs_str_cat(s, "\n<body>\n"); |
| 671 | 668 | ||
| 672 | /* top nav */ | 669 | /* top nav */ |
| 673 | s = xs_str_cat(s, "<nav class=\"snac-top-nav\">"); | 670 | s = xs_str_cat(s, "<nav class=\"snac-top-nav\">"); |
| 674 | 671 | ||
| 672 | xs *avatar = xs_dup(xs_dict_get(snac->config, "avatar")); | ||
| 673 | |||
| 674 | if (avatar == NULL || *avatar == '\0') { | ||
| 675 | xs_free(avatar); | ||
| 676 | avatar = xs_fmt("data:image/png;base64, %s", default_avatar_base64()); | ||
| 677 | } | ||
| 678 | |||
| 675 | { | 679 | { |
| 676 | xs *s1; | 680 | xs *s1; |
| 677 | 681 | ||