From 7f1cde55795f9a76c197b7d55b0b01e980e9c5d1 Mon Sep 17 00:00:00 2001 From: blankie Date: Mon, 3 Apr 2023 22:10:08 +0700 Subject: [PATCH] Add CSS --- CMakeLists.txt | 2 +- main.cpp | 3 ++- routes/css.cpp | 29 +++++++++++++++++++++++++++++ routes/home.cpp | 2 +- routes/{home.h => routes.h} | 1 + 5 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 routes/css.cpp rename routes/{home.h => routes.h} (73%) diff --git a/CMakeLists.txt b/CMakeLists.txt index abbaa7c..52ebd64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ add_link_options(${FLAGS}) add_executable(${PROJECT_NAME} main.cpp misc.cpp config.cpp servehelper.cpp blankie/serializer.cpp blankie/escape.cpp - routes/home.cpp) + routes/home.cpp routes/css.cpp) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20 diff --git a/main.cpp b/main.cpp index ef8f4ca..41d01af 100644 --- a/main.cpp +++ b/main.cpp @@ -3,7 +3,7 @@ #include #include "config.h" -#include "routes/home.h" +#include "routes/routes.h" int main(int argc, char** argv) { if (argc != 2) { @@ -23,6 +23,7 @@ int main(int argc, char** argv) { server.Get("/", [&](const httplib::Request& req, httplib::Response& res) { home_route(req, res, config); }); + server.Get("/style.css", css_route); if (config.bind_port != 0) { if (!server.bind_to_port(config.bind_host, config.bind_port)) { diff --git a/routes/css.cpp b/routes/css.cpp new file mode 100644 index 0000000..08dc066 --- /dev/null +++ b/routes/css.cpp @@ -0,0 +1,29 @@ +#include "routes.h" + +void css_route(const httplib::Request& req, httplib::Response& res) { + res.set_content(R"EOF( + + :root { + --background-color: black; + --text-color: white; + --accent-color: #962AC3; + --dark-accent-color: #7D3F7D; + --bright-accent-color: #DE6DE6; + } + + body { + background-color: var(--background-color); + color: var(--text-color); + } + + a { + color: var(--accent-color); + text-decoration: none; + } + a:hover { + color: var(--bright-accent-color); + text-decoration: underline; + } + + )EOF", "text/css"); +} diff --git a/routes/home.cpp b/routes/home.cpp index 1478f6c..6e093f0 100644 --- a/routes/home.cpp +++ b/routes/home.cpp @@ -1,4 +1,4 @@ -#include "home.h" +#include "routes.h" #include "../servehelper.h" void home_route(const httplib::Request& req, httplib::Response& res, const Config& config) { diff --git a/routes/home.h b/routes/routes.h similarity index 73% rename from routes/home.h rename to routes/routes.h index 1e2e530..49454dc 100644 --- a/routes/home.h +++ b/routes/routes.h @@ -5,3 +5,4 @@ struct Config; // forward declaration from config.h void home_route(const httplib::Request& req, httplib::Response& res, const Config& config); +void css_route(const httplib::Request& req, httplib::Response& res);