diff --git a/favicon.svg b/favicon.svg new file mode 100644 index 0000000..4cae83e --- /dev/null +++ b/favicon.svg @@ -0,0 +1,6 @@ + + + + 🐱 + + diff --git a/implementations/Catcrafts-Blog.cpp b/implementations/Catcrafts-Blog.cpp index b9f5273..47e0974 100644 --- a/implementations/Catcrafts-Blog.cpp +++ b/implementations/Catcrafts-Blog.cpp @@ -15,13 +15,13 @@ import std; using namespace Crafter::CppDOMBindings; export namespace Catcrafts { - std::vector* blogButtons = new std::vector(); + std::vector blogButtons; void RenderBlog() { - delete blogButtons; - blogButtons = new std::vector(); + blogButtons.clear(); std::string html = ""; - for(const BlogPost& post : *posts) { + for(const BlogPost& post : posts) { + std::cout << "test" << std::endl; // For preview, we'll limit the content to first 200 characters std::string previewContent = post.content; if(previewContent.length() > 200) { @@ -47,11 +47,11 @@ export namespace Catcrafts { )", post.slug, post.name, post.date, previewContent); } - main->SetInnerHTML(html); + main.SetInnerHTML(std::format(R"(
{}
)", html)); - for(const BlogPost& post : *posts) { + for(const BlogPost& post : posts) { // Add click listener to the entire post card - HtmlElementView& cardView = blogButtons->emplace_back(std::format("blog-post-{}", post.slug)); + HtmlElementView& cardView = blogButtons.emplace_back(std::format("blog-post-{}", post.slug)); cardView.AddClickListener([slug = post.slug](Crafter::MouseEvent e) { PushState("{}", "", std::format("/blog/{}", slug)); RenderRoot(std::format("/blog/{}", slug)); @@ -62,9 +62,9 @@ export namespace Catcrafts { void RenderBlogPost(const std::string_view slug) { std::cout << "render "<< std::endl; - for(const BlogPost& post : *posts) { + for(const BlogPost& post : posts) { if(post.slug == slug) { - main->SetInnerHTML(std::format(R"( + main.SetInnerHTML(std::format(R"(

{}

@@ -78,6 +78,6 @@ export namespace Catcrafts { } } - main->SetInnerHTML("

Post Not Found

The requested blog post could not be found.

"); + main.SetInnerHTML("

Post Not Found

The requested blog post could not be found.

"); } } \ No newline at end of file diff --git a/implementations/Catcrafts-Root.cpp b/implementations/Catcrafts-Root.cpp index 9c93bc6..1510169 100644 --- a/implementations/Catcrafts-Root.cpp +++ b/implementations/Catcrafts-Root.cpp @@ -29,7 +29,7 @@ namespace Catcrafts { std::cout << postSlug << std::endl; RenderBlogPost(postSlug); } else { - main->SetInnerHTML("

Post Not Found

The requested blog post could not be found.

"); + main.SetInnerHTML("

Post Not Found

The requested blog post could not be found.

"); } } else { RenderBlog(); //default route diff --git a/interfaces/Catcrafts-Blog.cppm b/interfaces/Catcrafts-Blog.cppm index 88fadd1..53b7e83 100644 --- a/interfaces/Catcrafts-Blog.cppm +++ b/interfaces/Catcrafts-Blog.cppm @@ -18,7 +18,25 @@ export namespace Catcrafts { std::string date; std::string content; }; - std::vector* posts = new std::vector{ + std::vector posts { + { + "In WASM, Exit doesn't mean done.", + "in-wasm-exit-doesnt-mean-done", + "2025-11-14", + R"(So if anyone looked at the source code for this website pefore this post you would have seen that every is allocated with new, for example this very blog was defined as std::vector posts = new std::vector{...

+ + Reason for this was that everything became corrupted when callbacking from JS, not knowing sure as to why this was the fastest solution, but after debugging the problem became clear.

+ + When we reach the end of int main() from the eyes of C++ we're finished, deconstruct everything and wrap it up. Unkowing that we just registered a bunch of event handlers with JS.

+ + This caused all the memory corruption errors since everything was destructed.

+ + Luckily this is a very simple fix of adding -fno-c++-static-destructors, and things like this are is also the reason i use clang instead of gcc.

+ + So now all examples and this site have been updated to use normal variables again.

+ + Stick around for the next post for the CI/CD nightmare (not for the faint of heart))" + }, { "Hello World!", "hello-world", diff --git a/interfaces/Catcrafts-Views.cppm b/interfaces/Catcrafts-Views.cppm index 950a4c8..7ffe25c 100644 --- a/interfaces/Catcrafts-Views.cppm +++ b/interfaces/Catcrafts-Views.cppm @@ -11,7 +11,7 @@ import Crafter.CppDOM; using namespace Crafter; export namespace Catcrafts { - HtmlElementView* body = new HtmlElementView("body", R"( + HtmlElementPtr body("body", R"(
)"); - HtmlElementView* head = new HtmlElementView("head", R"( + HtmlElementPtr head("head", R"( Catcrafts.net + )"); - HtmlElementView* main = new HtmlElementView("main"); + HtmlElementPtr main("main"); } diff --git a/project.json b/project.json index 8ac91e9..4166de7 100644 --- a/project.json +++ b/project.json @@ -6,7 +6,7 @@ "interfaces": ["interfaces/Catcrafts", "interfaces/Catcrafts-Views", "interfaces/Catcrafts-Blog", "interfaces/Catcrafts-Root"], "implementations": ["implementations/main", "implementations/Catcrafts-Blog", "implementations/Catcrafts-Root"], "target": "wasm32-wasi", - "additional_files": ["styles/styles.css", "robots.txt", "sitemap.xml"], + "additional_files": ["styles/styles.css", "robots.txt", "sitemap.xml", "favicon.svg"], "dependencies": [ { "path":"https://forgejo.catcrafts.net/Catcrafts/Crafter.CppDOM.git", diff --git a/sitemap.xml b/sitemap.xml index 43aed69..e9f6a01 100644 --- a/sitemap.xml +++ b/sitemap.xml @@ -1,4 +1,5 @@ - + + https://catcrafts.net/ @@ -8,4 +9,7 @@ https://catcrafts.net/blog/hello-world + + https://catcrafts.net/blog/in-wasm-exit-doesnt-mean-done + \ No newline at end of file