diff options
author | Trumeet <yuuta@yuuta.moe> | 2023-03-14 22:56:59 -0700 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2023-03-14 22:56:59 -0700 |
commit | 59fa629a62084f7f117c84bd8c710449a1c3f90e (patch) | |
tree | 2e41e78e31c769bc199b97830f41e8da229abba8 | |
parent | f8d5c565f1f3d191a511964cf95f9120b7b14c81 (diff) | |
download | hitokoto-59fa629a62084f7f117c84bd8c710449a1c3f90e.tar hitokoto-59fa629a62084f7f117c84bd8c710449a1c3f90e.tar.gz hitokoto-59fa629a62084f7f117c84bd8c710449a1c3f90e.tar.bz2 hitokoto-59fa629a62084f7f117c84bd8c710449a1c3f90e.zip |
Support /hitokoto.css
-rw-r--r-- | m2.c | 30 |
1 files changed, 22 insertions, 8 deletions
@@ -7,6 +7,7 @@ #include <errno.h> #include <stdlib.h> #include <assert.h> +#include <string.h> static sqlite3 *db = NULL; static sqlite3_stmt *stmt = NULL; @@ -38,6 +39,7 @@ int main(int argc, char **argv) { FCGX_Stream *in, *out, *err; FCGX_ParamArray envp; while(FCGX_Accept(&in, &out, &err, &envp) >= 0) { + const char *url = FCGX_GetParam("REQUEST_URI", envp); switch (r = sqlite3_step(stmt)) { case SQLITE_DONE: FCGX_FPrintF(out, @@ -62,14 +64,26 @@ int main(int argc, char **argv) { char *title_zh = (char *) sqlite3_column_text(stmt, 1); char *text = (char *) sqlite3_column_text(stmt, 2); char *text_zh = (char *) sqlite3_column_text(stmt, 3); - FCGX_FPrintF(out, - "Content-type: application/json\r\n" - "\r\n" - "{\"title\":\"%s\",\"title_zh\":\"%s\",\"text\":\"%s\",\"text_zh\":\"%s\"}\n", - title, - title_zh ? title_zh : "", - text, - text_zh ? text_zh : ""); + if (!strncmp(url, "/hitokoto.css", 13)) { + FCGX_FPrintF(out, + "Content-Type: text/css\r\n" + "\r\n" + "#hitokoto::before { content: \"%s\" }\n" + "#hitokoto::after { content: \"%s\" }\n" + "#hitokoto_zh::before { content: \"%s\" }\n" + "#hitokoto_zh::after { content: \"%s\" }\n", + text, title, + text_zh ? text_zh : "", title_zh ? title_zh : ""); + } else { + FCGX_FPrintF(out, + "Content-type: application/json\r\n" + "\r\n" + "{\"title\":\"%s\",\"title_zh\":\"%s\",\"text\":\"%s\",\"text_zh\":\"%s\"}\n", + title, + title_zh ? title_zh : "", + text, + text_zh ? text_zh : ""); + } break; } if ((r = sqlite3_reset(stmt))) { |