diff --git a/src/files.cpp b/src/files.cpp index 256b06b..f35796a 100644 --- a/src/files.cpp +++ b/src/files.cpp @@ -3,7 +3,7 @@ #include #include -std::string Files::load(const char* path) +std::string Files::load(const std::string& path) { std::ifstream file(path); std::stringstream ss; diff --git a/src/files.hpp b/src/files.hpp index f284b60..8d5d4f6 100644 --- a/src/files.hpp +++ b/src/files.hpp @@ -5,6 +5,6 @@ namespace Files { - std::string load(const char* path); + std::string load(const std::string& path); } diff --git a/src/main.cpp b/src/main.cpp index 21eed21..cfa4b3e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,25 +6,57 @@ #include #include #include +#include std::string data_index = Files::load("../static/index.html"); -std::string data_projects = Files::load("../static/public/html/projects.html"); -std::string data_contact = Files::load("../static/public/html/contact.html"); -std::string data_about = Files::load("../static/public/html/about.html"); -std::string data_resume = Files::load("../static/public/html/resume.html"); -std::string data_404 = Files::load("../static/public/html/error.html"); +std::string data_error = Files::load("../static/error.html"); httplib::Server svr; -auto page_handler(std::string data_content) +std::string theme_light = R"( +
+ +)"; + +std::string theme_dark = R"( +
+ +)"; + +std::string get_theme(const httplib::Request& req) { - return [data_content](const httplib::Request& req, httplib::Response& res) - { - std::string data = std::vformat(data_index, std::make_format_args(data_content)); - res.set_content(data, "text/html"); - }; + std::string cookies = req.get_header_value("Cookie"); + return regex_search(cookies, std::regex("(^|(; *))theme=light")) ? theme_light : theme_dark; } +struct page_handler +{ + std::string path; + + page_handler(std::string path) : path(path) {} + + void operator()(const httplib::Request& req, httplib::Response& res) + { + std::string data_content = Files::load(path); + std::string page = std::vformat(data_index, std::make_format_args(get_theme(req), data_content)); + res.set_content(page, "text/html"); + } +}; + +struct theme_handler +{ + std::string theme; + std::string content; + + theme_handler(std::string theme, std::string content) : theme(theme), content(content) {} + + void operator()(const httplib::Request& req, httplib::Response& res) + { + res.set_header("Set-Cookie", std::format("theme={}; Path=/; SameSite=Strict; HttpOnly; Max-Age=31536000", theme)); + res.set_content(content, "text/html"); + } +}; + void post_contact(const httplib::Request& req, httplib::Response& res) { std::cout << "Contact form submitted\n"; @@ -37,21 +69,22 @@ void post_contact(const httplib::Request& req, httplib::Response& res) void error_handler(const httplib::Request& req, httplib::Response& res) { - std::string data = std::vformat(data_index, std::make_format_args(data_404)); - res.set_content(data, "text/html"); + std::string page = std::vformat(data_index, std::make_format_args(get_theme(req), data_error)); + res.set_content(page, "text/html"); } int main() { svr.set_mount_point("/static", "../static/public/"); - svr.Get("/", page_handler(data_projects)); - svr.Get("/projects", page_handler(data_projects)); - svr.Get("/contact", page_handler(data_contact)); - svr.Get("/about", page_handler(data_about)); - svr.Get("/resume", page_handler(data_resume)); + svr.Get("/", page_handler("../static/public/html/projects.html")); + svr.Get("/projects", page_handler("../static/public/html/projects.html")); + svr.Get("/contact", page_handler("../static/public/html/contact.html")); + svr.Get("/about", page_handler("../static/public/html/about.html")); svr.Post("/contact", post_contact); + svr.Post("/theme/light", theme_handler("light", theme_light)); + svr.Post("/theme/dark", theme_handler("dark", theme_dark)); svr.set_error_handler(error_handler); diff --git a/static/public/html/error.html b/static/error.html similarity index 100% rename from static/public/html/error.html rename to static/error.html diff --git a/static/index.html b/static/index.html index 160f8e1..7b9b553 100644 --- a/static/index.html +++ b/static/index.html @@ -1,7 +1,7 @@ - + @@ -11,7 +11,7 @@
  • -
  • +
  • {}
  • diff --git a/static/public/css/dark.css b/static/public/css/dark.css new file mode 100644 index 0000000..0862106 --- /dev/null +++ b/static/public/css/dark.css @@ -0,0 +1,58 @@ + +h1, h2, h3, h4, h5, h6, p, li, th, td, label { + color: lightgray; +} + +a:link, .button-link { + color: #2b7bab; +} + +a:visited { + color: #0b8b8b; +} + +a:hover, .button-link:hover { + background-color: inherit; + color: #ab4b4b; +} + +input:focus, textarea:focus { + outline: none; +} + +input, button, textarea { + background-color: #101014; +} + +button, input, textarea { + color: lightgray; +} + +input[type="text"], input[type="email"], input[type="button"], textarea, button { + border-color: gray; +} + +button:hover { + background-color: #30303c; +} + +th, td { + border: 1px solid gray; +} + +ul.navbar { + background-color: #282830; +} + +ul.navbar button:hover { + background-color: #383846; +} + +html, body { + background-color: #101018; +} + +#root-head { + background-color: #202028; +} + diff --git a/static/public/css/light.css b/static/public/css/light.css new file mode 100644 index 0000000..a95f1e1 --- /dev/null +++ b/static/public/css/light.css @@ -0,0 +1,54 @@ + +button, input, textarea { + color: black; +} + +input[type="text"], input[type="email"], input[type="button"], textarea, button { + border-color: black; +} + +button:hover { + background-color: lightgray; +} + +h1, h2, h3, h4, h5, h6, p, li, th, td, label { + color: black; +} + +a:link, .button-link { + color: blue; +} + +a:visited { + color: purple; +} + +input, button, textarea { + background-color: white; +} + +a:hover, .button-link:hover { + background-color: inherit; + color: red; +} + +th, td { + border: 1px solid black; +} + +ul.navbar { + background-color: #c8c8d8; +} + +ul.navbar button:hover { + background-color: #b8b8c8; +} + +html, body { + background-color: #f0f0ff; +} + +#root-head { + background-color: #e0e0ee; +} + diff --git a/static/public/style.css b/static/public/css/style.css similarity index 76% rename from static/public/style.css rename to static/public/css/style.css index da6715b..c9a6318 100644 --- a/static/public/style.css +++ b/static/public/css/style.css @@ -1,4 +1,13 @@ +.button-link { + background: none; + border: none; + padding: 0; + font: inherit; + cursor: pointer; + text-decoration: underline; +} + img { width: calc(min(100%, 800px)); border-radius: 0.25em; @@ -9,7 +18,16 @@ button { font: inherit; cursor: pointer; text-decoration: none; - color: black; +} + +table { + border-collapse: collapse; + width: 100%; +} + +th, td { + text-align: left; + padding: 0.75em; } .visually-hidden { @@ -22,43 +40,40 @@ button { transform: translateY(-100%); } -.button-link { - background: none; - border: none; - padding: 0; - font: inherit; - cursor: pointer; - text-decoration: underline; - color: blue; -} - ul.navbar { list-style-type: none; - background-color: #c0c0c4; margin: 0; padding: 0; - display: flex; + overflow: hidden; } ul.navbar li { display: inline; + float: left; margin: 0; padding: 0; } -ul.navbar button { - background-color: #c0c0c4; +ul.navbar li button { + transition: 0.25s; + background-color: inherit; border: none; padding: 1em 1.5em; font: inherit; cursor: pointer; text-decoration: none; display: block; - color: black; } -ul.navbar button:hover { - background-color: #a0a0a4; +ul.navbar li#theme-target { + float: right; +} + +ul.navbar li#theme-target button { + font-size: 1.5em; + padding: 0; + height: 54px; + width: 54px; } input[type="text"], input[type="email"], textarea { @@ -71,7 +86,7 @@ input[type="text"], input[type="email"], input[type="button"], textarea, button border-width: thin; border-style: solid; border-color: gray; - padding: 0.25em 0.5em; + padding: 0.5em 0.75em; } textarea { @@ -84,7 +99,6 @@ label { } html, body { - background-color: #404044; height: 100%; margin: 0; padding: 0; @@ -93,7 +107,6 @@ html, body { #root-head { margin: 0 auto; padding: 0; - background-color: #e0e0e0; display: block; max-width: calc(max(80%, 800px)); min-height: 100%; diff --git a/static/public/html/about.html b/static/public/html/about.html index f4e0bee..98a653b 100644 --- a/static/public/html/about.html +++ b/static/public/html/about.html @@ -1,5 +1,46 @@ Jays Portfolio - About -

    About

    +

    About Me

    + + +

    Education

    + + + + + + + + + + + + + + + + +
    TimeLocationCourse
    2022 - PresentUniversity of TasmaniaBachelor of Information and Communication Technology
    2020 - 2021Hobart CollegeYear 11 and 12
    + +

    Experience

    + + + + + + + + + + + + + + + +
    TimeLocationRole
    2020 - PresentGoulds Natural Medicine - WebstoreFull Stack Developer - Contractor
    2019EditorKH - JumpcutterFrontend Developer - Internship
    + +

    Skills

    + diff --git a/static/public/html/resume.html b/static/public/html/resume.html deleted file mode 100644 index bffe6a6..0000000 --- a/static/public/html/resume.html +++ /dev/null @@ -1,5 +0,0 @@ - -Jays Portfolio - Resume - -

    Resume

    -