/* 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 :Root; import :Views; import std; using namespace Crafter::CppDOMBindings; export namespace Catcrafts { std::vector blogButtons; void RenderBlog() { blogButtons.clear(); std::string html = ""; 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) { // Find the last space before 200 characters to avoid cutting words std::size_t lastSpace = previewContent.find_last_of(' ', 200); if(lastSpace != std::string::npos) { previewContent = previewContent.substr(0, lastSpace) + "..."; } else { previewContent = previewContent.substr(0, 200) + "..."; } } html += std::format(R"(

{}

{}
)", post.slug, post.name, post.date, previewContent); } main.SetInnerHTML(std::format(R"(
{}
)", html)); for(const BlogPost& post : posts) { // Add click listener to the entire post card 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)); }); } } void RenderBlogPost(const std::string_view slug) { std::cout << "render "<< std::endl; for(const BlogPost& post : posts) { if(post.slug == slug) { main.SetInnerHTML(std::format(R"(

{}

{}
)", post.name, post.date, post.content)); return; } } main.SetInnerHTML("

Post Not Found

The requested blog post could not be found.

"); } }