2025-11-12 21:56:18 +01:00
|
|
|
/*
|
|
|
|
|
catcrafts.net
|
2026-07-18 23:27:41 +02:00
|
|
|
Copyright (C) 2026 Catcrafts
|
2025-11-12 21:56:18 +01:00
|
|
|
|
2026-07-18 23:27:41 +02:00
|
|
|
The source code of this website is made available for viewing purposes only.
|
2025-11-12 21:56:18 +01:00
|
|
|
No permission is granted to copy, modify, distribute, or create derivative works.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export module Catcrafts:Root_impl;
|
|
|
|
|
import :Root;
|
|
|
|
|
import :Views;
|
|
|
|
|
import :Blog;
|
2026-07-19 01:13:30 +02:00
|
|
|
import :Demo;
|
2026-07-18 23:27:41 +02:00
|
|
|
import Crafter.Graphics;
|
2025-11-12 21:56:18 +01:00
|
|
|
import std;
|
|
|
|
|
|
2026-07-18 23:27:41 +02:00
|
|
|
using namespace Crafter;
|
|
|
|
|
|
2025-11-12 21:56:18 +01:00
|
|
|
namespace Catcrafts {
|
|
|
|
|
void RenderRoot(const std::string_view route) {
|
2026-07-19 01:13:30 +02:00
|
|
|
// Every route change replaces <main>'s innerHTML, which would
|
|
|
|
|
// orphan the demo canvas if it's currently mounted inside a post.
|
|
|
|
|
// Detach + hide it first; the post renderer re-mounts if needed.
|
|
|
|
|
UnmountDemo();
|
|
|
|
|
|
2025-11-12 21:56:18 +01:00
|
|
|
std::string currentRoute = std::string(route);
|
2026-07-18 23:27:41 +02:00
|
|
|
|
2025-11-12 21:56:18 +01:00
|
|
|
if(currentRoute == "/blog" || currentRoute == "/") {
|
|
|
|
|
RenderBlog();
|
|
|
|
|
} else if(currentRoute.rfind("/blog/", 0) == 0) {
|
|
|
|
|
std::size_t pos = currentRoute.find_last_of('/');
|
|
|
|
|
if(pos != std::string::npos) {
|
|
|
|
|
std::string postSlug = currentRoute.substr(pos + 1);
|
|
|
|
|
RenderBlogPost(postSlug);
|
|
|
|
|
} else {
|
2026-07-18 23:27:41 +02:00
|
|
|
MainContent().SetInnerHTML("<h1>Post Not Found</h1><p>The requested blog post could not be found.</p>");
|
2025-11-12 21:56:18 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2026-07-18 23:27:41 +02:00
|
|
|
RenderBlog();
|
2025-11-12 21:56:18 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-07-18 23:27:41 +02:00
|
|
|
}
|