diff options
| author | 2024-09-04 09:48:35 +0200 | |
|---|---|---|
| committer | 2024-09-04 09:48:35 +0200 | |
| commit | 6778350211aeae076be80393cbef637e0218ad49 (patch) | |
| tree | af2edb5302be580629b62a1a454463e142b90842 | |
| parent | Added some CSS styling to the list-of-lists. (diff) | |
| download | snac2-6778350211aeae076be80393cbef637e0218ad49.tar.gz snac2-6778350211aeae076be80393cbef637e0218ad49.tar.xz snac2-6778350211aeae076be80393cbef637e0218ad49.zip | |
If style.css does not exist, it's created with the default one.
| -rw-r--r-- | data.c | 8 | ||||
| -rw-r--r-- | snac.h | 1 | ||||
| -rw-r--r-- | utils.c | 24 |
3 files changed, 27 insertions, 6 deletions
| @@ -156,6 +156,14 @@ int srv_open(const char *basedir, int auto_upgrade) | |||
| 156 | /* read (and drop) emojis.json, possibly creating it */ | 156 | /* read (and drop) emojis.json, possibly creating it */ |
| 157 | xs_free(emojis()); | 157 | xs_free(emojis()); |
| 158 | 158 | ||
| 159 | /* if style.css does not exist, create it */ | ||
| 160 | xs *css_fn = xs_fmt("%s/style.css", srv_basedir); | ||
| 161 | |||
| 162 | if (mtime(css_fn) == 0) { | ||
| 163 | srv_log(xs_fmt("Writing style.css")); | ||
| 164 | write_default_css(); | ||
| 165 | } | ||
| 166 | |||
| 159 | return ret; | 167 | return ret; |
| 160 | } | 168 | } |
| 161 | 169 | ||
| @@ -347,6 +347,7 @@ int html_post_handler(const xs_dict *req, const char *q_path, | |||
| 347 | char **body, int *b_size, char **ctype); | 347 | char **body, int *b_size, char **ctype); |
| 348 | xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc); | 348 | xs_str *timeline_to_rss(snac *user, const xs_list *timeline, char *title, char *link, char *desc); |
| 349 | 349 | ||
| 350 | int write_default_css(void); | ||
| 350 | int snac_init(const char *_basedir); | 351 | int snac_init(const char *_basedir); |
| 351 | int adduser(const char *uid); | 352 | int adduser(const char *uid); |
| 352 | int resetpwd(snac *snac); | 353 | int resetpwd(snac *snac); |
| @@ -107,6 +107,22 @@ static const char *greeting_html = | |||
| 107 | "<p>This site is powered by <abbr title=\"Social Networks Are Crap\">snac</abbr>.</p>\n" | 107 | "<p>This site is powered by <abbr title=\"Social Networks Are Crap\">snac</abbr>.</p>\n" |
| 108 | "</body></html>\n"; | 108 | "</body></html>\n"; |
| 109 | 109 | ||
| 110 | |||
| 111 | int write_default_css(void) | ||
| 112 | { | ||
| 113 | FILE *f; | ||
| 114 | |||
| 115 | xs *sfn = xs_fmt("%s/style.css", srv_basedir); | ||
| 116 | if ((f = fopen(sfn, "w")) == NULL) | ||
| 117 | return 1; | ||
| 118 | |||
| 119 | fwrite(default_css, strlen(default_css), 1, f); | ||
| 120 | fclose(f); | ||
| 121 | |||
| 122 | return 0; | ||
| 123 | } | ||
| 124 | |||
| 125 | |||
| 110 | int snac_init(const char *basedir) | 126 | int snac_init(const char *basedir) |
| 111 | { | 127 | { |
| 112 | FILE *f; | 128 | FILE *f; |
| @@ -217,15 +233,11 @@ int snac_init(const char *basedir) | |||
| 217 | fwrite(gh, strlen(gh), 1, f); | 233 | fwrite(gh, strlen(gh), 1, f); |
| 218 | fclose(f); | 234 | fclose(f); |
| 219 | 235 | ||
| 220 | xs *sfn = xs_fmt("%s/style.css", srv_basedir); | 236 | if (write_default_css()) { |
| 221 | if ((f = fopen(sfn, "w")) == NULL) { | 237 | printf("ERROR: cannot create style.css\n"); |
| 222 | printf("ERROR: cannot create '%s'\n", sfn); | ||
| 223 | return 1; | 238 | return 1; |
| 224 | } | 239 | } |
| 225 | 240 | ||
| 226 | fwrite(default_css, strlen(default_css), 1, f); | ||
| 227 | fclose(f); | ||
| 228 | |||
| 229 | xs *cfn = xs_fmt("%s/server.json", srv_basedir); | 241 | xs *cfn = xs_fmt("%s/server.json", srv_basedir); |
| 230 | if ((f = fopen(cfn, "w")) == NULL) { | 242 | if ((f = fopen(cfn, "w")) == NULL) { |
| 231 | printf("ERROR: cannot create '%s'\n", cfn); | 243 | printf("ERROR: cannot create '%s'\n", cfn); |