commit 7d7110c

default  ·  2023-11-23 22:33:57 +0000 UTC
parent 073140e
New function html_base_head().
1 files changed,  +42, -12
M html.c
M html.c
+42, -12
 1@@ -380,7 +380,7 @@ xs_html *html_note(snac *user, char *summary,
 2 }
 3 
 4 
 5-xs_str *html_base_header(xs_str *s)
 6+static xs_str *html_base_header(xs_str *s)
 7 {
 8     xs_list *p;
 9     xs_str *v;
10@@ -402,9 +402,34 @@ xs_str *html_base_header(xs_str *s)
11 }
12 
13 
14+static xs_html *html_base_head(void)
15+{
16+    xs_html *head = xs_html_tag("head",
17+        xs_html_sctag("meta",
18+            xs_html_attr("name", "viewport"),
19+            xs_html_attr("content", "width=device-width, initial-scale=1")),
20+        xs_html_sctag("meta",
21+            xs_html_attr("name", "generator"),
22+            xs_html_attr("content", USER_AGENT)));
23+
24+    /* add server CSS */
25+    xs_list *p = xs_dict_get(srv_config, "cssurls");
26+    char *v;
27+    while (xs_list_iter(&p, &v)) {
28+        xs_html_add(head,
29+            xs_html_sctag("link",
30+                xs_html_attr("rel",  "stylesheet"),
31+                xs_html_attr("type", "text/css"),
32+                xs_html_attr("href", v)));
33+    }
34+
35+    return head;
36+}
37+
38+
39 xs_str *html_instance_header(xs_str *s, char *tag)
40 {
41-    s = html_base_header(s);
42+    xs_html *head = html_base_head();
43 
44     {
45         FILE *f;
46@@ -414,23 +439,28 @@ xs_str *html_instance_header(xs_str *s, char *tag)
47             xs *css = xs_readall(f);
48             fclose(f);
49 
50-            xs *s1 = xs_fmt("<style>%s</style>\n", css);
51-            s = xs_str_cat(s, s1);
52+            xs_html_add(head,
53+                xs_html_tag("style",
54+                    xs_html_text(css)));
55         }
56     }
57 
58-    const char *host  = xs_dict_get(srv_config, "host");
59-    const char *title = xs_dict_get(srv_config, "title");
60-    const char *sdesc = xs_dict_get(srv_config, "short_description");
61-    const char *email = xs_dict_get(srv_config, "admin_email");
62-    const char *acct  = xs_dict_get(srv_config, "admin_account");
63+    char *host  = xs_dict_get(srv_config, "host");
64+    char *title = xs_dict_get(srv_config, "title");
65+    char *sdesc = xs_dict_get(srv_config, "short_description");
66+    char *email = xs_dict_get(srv_config, "admin_email");
67+    char *acct  = xs_dict_get(srv_config, "admin_account");
68+
69+    xs_html_add(head,
70+        xs_html_tag("title",
71+            xs_html_text(title && *title ? title : host)));
72 
73     {
74-        xs *s1 = xs_fmt("<title>%s</title>\n", title && *title ? title : host);
75-        s = xs_str_cat(s, s1);
76+        xs *s1 = xs_html_render(head);
77+        s = xs_str_cat(s, "<!DOCTYPE html><html>\n", s1);
78     }
79 
80-    s = xs_str_cat(s, "</head>\n<body>\n");
81+    s = xs_str_cat(s, "<body>\n");
82 
83     s = xs_str_cat(s, "<div class=\"snac-instance-blurb\">\n");
84