From 8079e5e0189782457491b386db44b7b3c632bd01 Mon Sep 17 00:00:00 2001 From: Jay Robson Date: Wed, 8 May 2024 15:06:40 +1000 Subject: [PATCH] refactor --- src/main.cpp | 2 + src/page/nav_targets.cpp | 26 +++++++--- src/page/projects.cpp | 49 +++++++++++++++++++ src/page/projects.hpp | 12 +++++ static/{public/html => }/about.html | 0 static/{public/html => }/contact.html | 0 static/index.html | 6 +-- static/projects.html | 19 +++++++ .../html => }/projects/fast_nuclear_sim.html | 0 .../html => }/projects/goulds_webstore.html | 2 +- .../html => }/projects/project_zombie.html | 0 .../projects/this_portfolio_website.html | 0 static/public/css/style.css | 18 +++++++ static/public/html/projects.html | 19 ------- 14 files changed, 122 insertions(+), 31 deletions(-) create mode 100644 src/page/projects.cpp create mode 100644 src/page/projects.hpp rename static/{public/html => }/about.html (100%) rename static/{public/html => }/contact.html (100%) create mode 100644 static/projects.html rename static/{public/html => }/projects/fast_nuclear_sim.html (100%) rename static/{public/html => }/projects/goulds_webstore.html (96%) rename static/{public/html => }/projects/project_zombie.html (100%) rename static/{public/html => }/projects/this_portfolio_website.html (100%) delete mode 100644 static/public/html/projects.html diff --git a/src/main.cpp b/src/main.cpp index a2e31ee..09b9c46 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "page/contact.hpp" #include "page/error_handler.hpp" #include "page/nav_targets.hpp" +#include "page/projects.hpp" #include #include @@ -16,6 +17,7 @@ int main() Page::NavTargets::Init(svr); Page::Contact::Init(svr); Page::ErrorHandler::Init(svr); + Page::Projects::Init(svr); std::cout << "Listening on port 8080\n"; svr.listen("0.0.0.0", 8080); diff --git a/src/page/nav_targets.cpp b/src/page/nav_targets.cpp index fee57e7..2d7fdac 100644 --- a/src/page/nav_targets.cpp +++ b/src/page/nav_targets.cpp @@ -9,24 +9,34 @@ using namespace Page; struct page_handler { - std::string path; + std::string content; - page_handler(std::string path) : path(path) {} + page_handler(std::string path) + { + content = Files::Load(path); + } void operator()(const httplib::Request& req, httplib::Response& res) { - std::string data_content = Files::Load(path); + if(req.has_header("hx-request")) + { + res.set_content(content, "text/html"); + return; + } + std::string theme = Theme::Get(req); - std::string page = std::vformat(Root::DATA_INDEX, std::make_format_args(theme, data_content)); + std::string page = std::vformat(Root::DATA_INDEX, std::make_format_args(theme, content)); res.set_content(page, "text/html"); } }; void NavTargets::Init(httplib::Server &svr) { - 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")); + page_handler projects_handler = page_handler("../static/projects.html"); + + svr.Get("/", projects_handler); + svr.Get("/projects", projects_handler); + svr.Get("/contact", page_handler("../static/contact.html")); + svr.Get("/about", page_handler("../static/about.html")); } diff --git a/src/page/projects.cpp b/src/page/projects.cpp new file mode 100644 index 0000000..6be3c70 --- /dev/null +++ b/src/page/projects.cpp @@ -0,0 +1,49 @@ + +#include "projects.hpp" +#include "../files.hpp" +#include "root.hpp" +#include "theme.hpp" +#include +#include + +using namespace Page; + +static const std::string PROJECTS_INDEX = Files::Load("../static/projects.html"); + +struct project_handler +{ + std::string content; + + project_handler() + { + + } + + project_handler(std::string path) + { + content = Files::Load(path); + } + + void operator()(const httplib::Request& req, httplib::Response& res) + { + if(req.has_header("hx-request")) + { + res.set_content(content, "text/html"); + return; + } + + std::string theme = Theme::Get(req); + std::string content_projects = std::regex_replace(PROJECTS_INDEX, std::regex(""), content); + std::string page = std::vformat(Root::DATA_INDEX, std::make_format_args(theme, content_projects)); + res.set_content(page, "text/html"); + } +}; + +void Projects::Init(httplib::Server& svr) +{ + svr.Get("/projects/fast_nuclear_sim", project_handler("../static/projects/fast_nuclear_sim.html")); + svr.Get("/projects/goulds_webstore", project_handler("../static/projects/goulds_webstore.html")); + svr.Get("/projects/project_zombie", project_handler("../static/projects/project_zombie.html")); + svr.Get("/projects/this_portfolio_website", project_handler("../static/projects/this_portfolio_website.html")); +} + diff --git a/src/page/projects.hpp b/src/page/projects.hpp new file mode 100644 index 0000000..6bf6c36 --- /dev/null +++ b/src/page/projects.hpp @@ -0,0 +1,12 @@ + +#pragma once + +#include "../cpp-httplib/httplib.h" + +namespace Page::Projects +{ + +void Init(httplib::Server& srv); + +}; + diff --git a/static/public/html/about.html b/static/about.html similarity index 100% rename from static/public/html/about.html rename to static/about.html diff --git a/static/public/html/contact.html b/static/contact.html similarity index 100% rename from static/public/html/contact.html rename to static/contact.html diff --git a/static/index.html b/static/index.html index e11d933..274ca07 100644 --- a/static/index.html +++ b/static/index.html @@ -12,9 +12,9 @@
diff --git a/static/projects.html b/static/projects.html new file mode 100644 index 0000000..5f54687 --- /dev/null +++ b/static/projects.html @@ -0,0 +1,19 @@ + +Jays Portfolio + +

Welcome to my portfolio website :)

+

+ Here you can see the (more notable) projects I have created and/or worked on, or click/activate all the buttons to find out more about me. +

+

+ Also please feel free to check out my GitHub and Gitea + profiles if you would like to see the projects that aren't on here. +

+
    +
  • +
  • +
  • +
  • +
+
+ diff --git a/static/public/html/projects/fast_nuclear_sim.html b/static/projects/fast_nuclear_sim.html similarity index 100% rename from static/public/html/projects/fast_nuclear_sim.html rename to static/projects/fast_nuclear_sim.html diff --git a/static/public/html/projects/goulds_webstore.html b/static/projects/goulds_webstore.html similarity index 96% rename from static/public/html/projects/goulds_webstore.html rename to static/projects/goulds_webstore.html index 55a3c7f..354fe13 100644 --- a/static/public/html/projects/goulds_webstore.html +++ b/static/projects/goulds_webstore.html @@ -22,6 +22,6 @@

Links

diff --git a/static/public/html/projects/project_zombie.html b/static/projects/project_zombie.html similarity index 100% rename from static/public/html/projects/project_zombie.html rename to static/projects/project_zombie.html diff --git a/static/public/html/projects/this_portfolio_website.html b/static/projects/this_portfolio_website.html similarity index 100% rename from static/public/html/projects/this_portfolio_website.html rename to static/projects/this_portfolio_website.html diff --git a/static/public/css/style.css b/static/public/css/style.css index 021a560..b9f4ba0 100644 --- a/static/public/css/style.css +++ b/static/public/css/style.css @@ -14,6 +14,9 @@ p, label, th, td, li { img { width: calc(min(100%, 800px)); +} + +img, iframe { border-radius: 4px; border-style: none; } @@ -106,6 +109,21 @@ html, body { padding: 0; } +.responsive-iframe { + width: 100%; + height: 0; + padding-top: 56.25%; + position: relative; +} + +.responsive-iframe iframe { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} + #root-head { margin: 0 auto; padding: 0; diff --git a/static/public/html/projects.html b/static/public/html/projects.html deleted file mode 100644 index 58bd300..0000000 --- a/static/public/html/projects.html +++ /dev/null @@ -1,19 +0,0 @@ - -Jays Portfolio - -

Welcome to my portfolio website :)

-

- Here you can see the (more notable) projects I have created and/or worked on, or click/activate all the buttons to find out more about me. -

-

- Also please feel free to check out my GitHub and Gitea - profiles if you would like to see the projects that aren't on here. -

-
    -
  • -
  • -
  • -
  • -
-
-