From cef5a320411ce7b1e3ef15826f2856f25e3f0b60 Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Wed, 12 Nov 2025 20:58:07 +0100 Subject: [PATCH] inital commit --- .gitignore | 2 ++ LICENSE | 2 ++ implementations/Catcrafts-Blog.cpp | 22 ++++++++++++ implementations/main.cpp | 56 +++++++++++++++++++++++++++++ interfaces/Catcrafts-Blog.cppm | 28 +++++++++++++++ interfaces/Catcrafts-Component.cppm | 16 +++++++++ interfaces/Catcrafts-Views.cppm | 16 +++++++++ interfaces/Catcrafts.cppm | 11 ++++++ project.json | 17 +++++++++ run.sh | 1 + 10 files changed, 171 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 implementations/Catcrafts-Blog.cpp create mode 100644 implementations/main.cpp create mode 100644 interfaces/Catcrafts-Blog.cppm create mode 100644 interfaces/Catcrafts-Component.cppm create mode 100644 interfaces/Catcrafts-Views.cppm create mode 100644 interfaces/Catcrafts.cppm create mode 100644 project.json create mode 100755 run.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4e9c87a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +bin/ \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..75ee96c --- /dev/null +++ b/LICENSE @@ -0,0 +1,2 @@ +The source code of this website is made available for viewing purposes only. +No permission is granted to copy, modify, distribute, or create derivative works. diff --git a/implementations/Catcrafts-Blog.cpp b/implementations/Catcrafts-Blog.cpp new file mode 100644 index 0000000..e634a1e --- /dev/null +++ b/implementations/Catcrafts-Blog.cpp @@ -0,0 +1,22 @@ +/* +catcrafts.net +Copyright (C) 2025 Catcrafts + +The source code of this website is made available for viewing purposes only. +No permission is granted to copy, modify, distribute, or create derivative works. +*/ + +export module Catcrafts:Blog_impl; +import :Blog; +import std; + +namespace Catcrafts { + std::string RenderBlog() { + std::string html = ""; + for(const BlogPost& post : *posts) { + html += std::format("{}
{}

{}", post.name, post.date, post.content); + } + return html; + } +} + diff --git a/implementations/main.cpp b/implementations/main.cpp new file mode 100644 index 0000000..256d2be --- /dev/null +++ b/implementations/main.cpp @@ -0,0 +1,56 @@ +/* +catcrafts.net +Copyright (C) 2025 Catcrafts + +The source code of this website is made available for viewing purposes only. +No permission is granted to copy, modify, distribute, or create derivative works. +*/ + +import Catcrafts; +import Crafter.CppDOM; +import std; +using namespace Catcrafts; +using namespace Crafter; +using namespace Crafter::CppDOMBindings; + +HtmlElementView* blogButton; + +void RenderRoot(const std::string_view route) { + std::string pageContent; + if(route == "/blog") { //currently pointless if but for adding more pages in the future + pageContent = RenderBlog(); + } else { + pageContent = RenderBlog(); //default route + } + + body->SetInnerHTML(std::format(R"( +Catcrafts.net + + +{} + +)", pageContent)); + + if(blogButton) { + delete blogButton; + } + blogButton = new HtmlElementView("blog-nav-button"); + blogButton->AddClickListener([](Crafter::MouseEvent e) { + std::cout << "click" << std::endl; + PushState("{}", "", "/blog"); + RenderRoot("blog"); + }); +} + +int main() { + AddPopStateListener([]() { + RenderRoot(GetPathNameString()); + }); + + RenderRoot("/"); +} \ No newline at end of file diff --git a/interfaces/Catcrafts-Blog.cppm b/interfaces/Catcrafts-Blog.cppm new file mode 100644 index 0000000..71ed231 --- /dev/null +++ b/interfaces/Catcrafts-Blog.cppm @@ -0,0 +1,28 @@ +/* +catcrafts.net +Copyright (C) 2025 Catcrafts + +The source code of this website is made available for viewing purposes only. +No permission is granted to copy, modify, distribute, or create derivative works. +*/ + +export module Catcrafts:Blog; +import Crafter.CppDOM; +import std; +using namespace Crafter; + +export namespace Catcrafts { + struct BlogPost { + std::string name; + std::string date; + std::string content; + }; + std::vector* posts = new std::vector{ + { + "First post!", + "2025-11-12", + "Welcome to catcrafts.net!" + } + }; + std::string RenderBlog(); +} diff --git a/interfaces/Catcrafts-Component.cppm b/interfaces/Catcrafts-Component.cppm new file mode 100644 index 0000000..1996871 --- /dev/null +++ b/interfaces/Catcrafts-Component.cppm @@ -0,0 +1,16 @@ +/* +catcrafts.net +Copyright (C) 2025 Catcrafts + +The source code of this website is made available for viewing purposes only. +No permission is granted to copy, modify, distribute, or create derivative works. +*/ + +export module Catcrafts:Component; +using namespace Crafter; + +export namespace Catcrafts { + class Component { + std::string render(); + }; +} diff --git a/interfaces/Catcrafts-Views.cppm b/interfaces/Catcrafts-Views.cppm new file mode 100644 index 0000000..7c8ede8 --- /dev/null +++ b/interfaces/Catcrafts-Views.cppm @@ -0,0 +1,16 @@ +/* +catcrafts.net +Copyright (C) 2025 Catcrafts + +The source code of this website is made available for viewing purposes only. +No permission is granted to copy, modify, distribute, or create derivative works. +*/ + +export module Catcrafts:Views; +import Crafter.CppDOM; +using namespace Crafter; + +export namespace Catcrafts { + HtmlElementView* body = new HtmlElementView("body"); + HtmlElementView* head = new HtmlElementView("head"); +} diff --git a/interfaces/Catcrafts.cppm b/interfaces/Catcrafts.cppm new file mode 100644 index 0000000..457009d --- /dev/null +++ b/interfaces/Catcrafts.cppm @@ -0,0 +1,11 @@ +/* +catcrafts.net +Copyright (C) 2025 Catcrafts + +The source code of this website is made available for viewing purposes only. +No permission is granted to copy, modify, distribute, or create derivative works. +*/ + +export module Catcrafts; +export import :Views; +export import :Blog; \ No newline at end of file diff --git a/project.json b/project.json new file mode 100644 index 0000000..f55107c --- /dev/null +++ b/project.json @@ -0,0 +1,17 @@ +{ + "name": "main", + "configurations": [ + { + "name": "executable", + "interfaces": ["interfaces/Catcrafts", "interfaces/Catcrafts-Views", "interfaces/Catcrafts-Blog"], + "implementations": ["implementations/main", "implementations/Catcrafts-Blog"], + "target": "wasm32-wasi", + "dependencies": [ + { + "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.CppDOM.git", + "configuration":"lib" + } + ] + } + ] +} \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..4ef65c1 --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +caddy file-server --listen :8085 --root bin/executable \ No newline at end of file