diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-07-11 01:20:39 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-07-11 01:49:12 +0200 |
| commit | e79e955d93e24a192c9bf94181294d0797e9fded (patch) | |
| tree | 5c3697710b6aa004bb7e3747f4c8ba98b37d662d /page.c | |
| parent | 4236c7fc3a7c7ef9f79b045cfd99c6575b16f7b1 (diff) | |
Allow admins to define their own stylesheet
slcl used to provide a hardcoded stylesheet. However, it would be
desirable for some admins to provide a custom stylesheet without having
to rebuild the application.
Now, slcl creates a default stylesheet, namely style.css, into the
target directory, that can be later modified by admins.
While this might contradict the suckless philosophy a bit, hopefully
some admins might find this new feature useful.
Diffstat (limited to 'page.c')
| -rw-r--r-- | page.c | 80 |
1 files changed, 26 insertions, 54 deletions
@@ -1535,73 +1535,45 @@ int page_bad_request(struct http_response *const r) return 0; } -int page_style(struct http_response *const r) +int page_style(struct http_response *const r, const char *const path) { - static const char body[] = - "body\n" - "{\n" - " font-family: 'Courier New', Courier, monospace;\n" - "}\n" - "td\n" - "{\n" - " font-size: 14px;\n" - "}\n" - "a\n" - "{\n" - " text-decoration: none;\n" - "}\n" - ".userform\n" - "{\n" - " padding: 4px;\n" - "}\n" - ".loginform\n" - "{\n" - " display: grid;\n" - "}\n" - "form, label, table\n" - "{\n" - " margin: auto;\n" - "}\n" - "div\n" - "{\n" - " align-items: center;\n" - " display: grid;\n" - "}\n" - "input, .abutton\n" - "{\n" - " margin: auto;\n" - " border: 1px solid;\n" - " border-radius: 8px;\n" - "}\n" - "header, footer\n" - "{\n" - " display: flex;\n" - " justify-content: center;\n" - " text-decoration: auto;\n" - "}\n" - "table\n" - "{\n" - " max-width: 50%;\n" - "}\n" - "tr:nth-child(even)\n" - "{\n" - " background-color: lightgray;\n" - "}\n"; + FILE *f = NULL; + struct stat sb; + + if (stat(path, &sb)) + { + fprintf(stderr, "%s: stat(2): %s\n", __func__, strerror(errno)); + goto failure; + } + else if (!(f = fopen(path, "rb"))) + { + fprintf(stderr, "%s: fopen(3) %s: %s\n", + __func__, path, strerror(errno)); + goto failure; + } *r = (const struct http_response) { .status = HTTP_STATUS_OK, - .buf.ro = body, - .n = sizeof body - 1 + .f = f, + .n = sb.st_size }; if (http_response_add_header(r, "Content-Type", "text/css")) { fprintf(stderr, "%s: http_response_add_header failed\n", __func__); - return -1; + goto failure; } return 0; + +failure: + + if (f && fclose(f)) + fprintf(stderr, "%s: fclose(3) %s: %s\n", + __func__, path, strerror(errno)); + + return -1; } int page_share(struct http_response *const r, const char *const path) |
