diff options
| author | 2023-11-23 23:33:57 +0100 | |
|---|---|---|
| committer | 2023-11-23 23:33:57 +0100 | |
| commit | 7d7110cb3b1262d348510ab686e7139f60a04791 (patch) | |
| tree | 314230dca0468d79cd362206f49b41da0997d2bc /html.c | |
| parent | The post edit box also uses html_note(). (diff) | |
| download | snac2-7d7110cb3b1262d348510ab686e7139f60a04791.tar.gz snac2-7d7110cb3b1262d348510ab686e7139f60a04791.tar.xz snac2-7d7110cb3b1262d348510ab686e7139f60a04791.zip | |
New function html_base_head().
Diffstat (limited to 'html.c')
| -rw-r--r-- | html.c | 54 |
1 files changed, 42 insertions, 12 deletions
| @@ -380,7 +380,7 @@ xs_html *html_note(snac *user, char *summary, | |||
| 380 | } | 380 | } |
| 381 | 381 | ||
| 382 | 382 | ||
| 383 | xs_str *html_base_header(xs_str *s) | 383 | static xs_str *html_base_header(xs_str *s) |
| 384 | { | 384 | { |
| 385 | xs_list *p; | 385 | xs_list *p; |
| 386 | xs_str *v; | 386 | xs_str *v; |
| @@ -402,9 +402,34 @@ xs_str *html_base_header(xs_str *s) | |||
| 402 | } | 402 | } |
| 403 | 403 | ||
| 404 | 404 | ||
| 405 | static xs_html *html_base_head(void) | ||
| 406 | { | ||
| 407 | xs_html *head = xs_html_tag("head", | ||
| 408 | xs_html_sctag("meta", | ||
| 409 | xs_html_attr("name", "viewport"), | ||
| 410 | xs_html_attr("content", "width=device-width, initial-scale=1")), | ||
| 411 | xs_html_sctag("meta", | ||
| 412 | xs_html_attr("name", "generator"), | ||
| 413 | xs_html_attr("content", USER_AGENT))); | ||
| 414 | |||
| 415 | /* add server CSS */ | ||
| 416 | xs_list *p = xs_dict_get(srv_config, "cssurls"); | ||
| 417 | char *v; | ||
| 418 | while (xs_list_iter(&p, &v)) { | ||
| 419 | xs_html_add(head, | ||
| 420 | xs_html_sctag("link", | ||
| 421 | xs_html_attr("rel", "stylesheet"), | ||
| 422 | xs_html_attr("type", "text/css"), | ||
| 423 | xs_html_attr("href", v))); | ||
| 424 | } | ||
| 425 | |||
| 426 | return head; | ||
| 427 | } | ||
| 428 | |||
| 429 | |||
| 405 | xs_str *html_instance_header(xs_str *s, char *tag) | 430 | xs_str *html_instance_header(xs_str *s, char *tag) |
| 406 | { | 431 | { |
| 407 | s = html_base_header(s); | 432 | xs_html *head = html_base_head(); |
| 408 | 433 | ||
| 409 | { | 434 | { |
| 410 | FILE *f; | 435 | FILE *f; |
| @@ -414,23 +439,28 @@ xs_str *html_instance_header(xs_str *s, char *tag) | |||
| 414 | xs *css = xs_readall(f); | 439 | xs *css = xs_readall(f); |
| 415 | fclose(f); | 440 | fclose(f); |
| 416 | 441 | ||
| 417 | xs *s1 = xs_fmt("<style>%s</style>\n", css); | 442 | xs_html_add(head, |
| 418 | s = xs_str_cat(s, s1); | 443 | xs_html_tag("style", |
| 444 | xs_html_text(css))); | ||
| 419 | } | 445 | } |
| 420 | } | 446 | } |
| 421 | 447 | ||
| 422 | const char *host = xs_dict_get(srv_config, "host"); | 448 | char *host = xs_dict_get(srv_config, "host"); |
| 423 | const char *title = xs_dict_get(srv_config, "title"); | 449 | char *title = xs_dict_get(srv_config, "title"); |
| 424 | const char *sdesc = xs_dict_get(srv_config, "short_description"); | 450 | char *sdesc = xs_dict_get(srv_config, "short_description"); |
| 425 | const char *email = xs_dict_get(srv_config, "admin_email"); | 451 | char *email = xs_dict_get(srv_config, "admin_email"); |
| 426 | const char *acct = xs_dict_get(srv_config, "admin_account"); | 452 | char *acct = xs_dict_get(srv_config, "admin_account"); |
| 453 | |||
| 454 | xs_html_add(head, | ||
| 455 | xs_html_tag("title", | ||
| 456 | xs_html_text(title && *title ? title : host))); | ||
| 427 | 457 | ||
| 428 | { | 458 | { |
| 429 | xs *s1 = xs_fmt("<title>%s</title>\n", title && *title ? title : host); | 459 | xs *s1 = xs_html_render(head); |
| 430 | s = xs_str_cat(s, s1); | 460 | s = xs_str_cat(s, "<!DOCTYPE html><html>\n", s1); |
| 431 | } | 461 | } |
| 432 | 462 | ||
| 433 | s = xs_str_cat(s, "</head>\n<body>\n"); | 463 | s = xs_str_cat(s, "<body>\n"); |
| 434 | 464 | ||
| 435 | s = xs_str_cat(s, "<div class=\"snac-instance-blurb\">\n"); | 465 | s = xs_str_cat(s, "<div class=\"snac-instance-blurb\">\n"); |
| 436 | 466 | ||