From 59fa629a62084f7f117c84bd8c710449a1c3f90e Mon Sep 17 00:00:00 2001 From: Trumeet Date: Tue, 14 Mar 2023 22:56:59 -0700 Subject: Support /hitokoto.css --- m2.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/m2.c b/m2.c index 32e1dba..cb83d91 100644 --- a/m2.c +++ b/m2.c @@ -7,6 +7,7 @@ #include #include #include +#include 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))) { -- cgit v1.2.3