commit 6778350

default  ·  2024-09-04 07:48:35 +0000 UTC
parent d8e77ac
If style.css does not exist, it's created with the default one.
3 files changed,  +27, -6
M data.c
M snac.h
M data.c
+8, -0
 1@@ -156,6 +156,14 @@ int srv_open(const char *basedir, int auto_upgrade)
 2     /* read (and drop) emojis.json, possibly creating it */
 3     xs_free(emojis());
 4 
 5+    /* if style.css does not exist, create it */
 6+    xs *css_fn = xs_fmt("%s/style.css", srv_basedir);
 7+
 8+    if (mtime(css_fn) == 0) {
 9+        srv_log(xs_fmt("Writing style.css"));
10+        write_default_css();
11+    }
12+
13     return ret;
14 }
15 
M snac.h
+1, -0
1@@ -347,6 +347,7 @@ int html_post_handler(const xs_dict *req, const char *q_path,
2                       char **body, int *b_size, char **ctype);
3 xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc);
4 
5+int write_default_css(void);
6 int snac_init(const char *_basedir);
7 int adduser(const char *uid);
8 int resetpwd(snac *snac);
+18, -6
 1@@ -107,6 +107,22 @@ static const char *greeting_html =
 2     "<p>This site is powered by <abbr title=\"Social Networks Are Crap\">snac</abbr>.</p>\n"
 3     "</body></html>\n";
 4 
 5+
 6+int write_default_css(void)
 7+{
 8+    FILE *f;
 9+
10+    xs *sfn = xs_fmt("%s/style.css", srv_basedir);
11+    if ((f = fopen(sfn, "w")) == NULL)
12+        return 1;
13+
14+    fwrite(default_css, strlen(default_css), 1, f);
15+    fclose(f);
16+
17+    return 0;
18+}
19+
20+
21 int snac_init(const char *basedir)
22 {
23     FILE *f;
24@@ -217,15 +233,11 @@ int snac_init(const char *basedir)
25     fwrite(gh, strlen(gh), 1, f);
26     fclose(f);
27 
28-    xs *sfn = xs_fmt("%s/style.css", srv_basedir);
29-    if ((f = fopen(sfn, "w")) == NULL) {
30-        printf("ERROR: cannot create '%s'\n", sfn);
31+    if (write_default_css()) {
32+        printf("ERROR: cannot create style.css\n");
33         return 1;
34     }
35 
36-    fwrite(default_css, strlen(default_css), 1, f);
37-    fclose(f);
38-
39     xs *cfn = xs_fmt("%s/server.json", srv_basedir);
40     if ((f = fopen(cfn, "w")) == NULL) {
41         printf("ERROR: cannot create '%s'\n", cfn);