2025-11-12 21:56:18 +01:00
|
|
|
/*
|
|
|
|
|
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:Root_impl;
|
|
|
|
|
import :Root;
|
|
|
|
|
import :Views;
|
|
|
|
|
import :Blog;
|
|
|
|
|
import std;
|
|
|
|
|
|
|
|
|
|
namespace Catcrafts {
|
|
|
|
|
void RenderRoot(const std::string_view route) {
|
|
|
|
|
std::string currentRoute = std::string(route);
|
|
|
|
|
|
|
|
|
|
if(currentRoute == "/blog" || currentRoute == "/") {
|
|
|
|
|
RenderBlog();
|
|
|
|
|
} else if(currentRoute.rfind("/blog/", 0) == 0) {
|
|
|
|
|
// Handle individual blog post routes like /blog/0, /blog/1, etc.
|
|
|
|
|
std::size_t pos = currentRoute.find_last_of('/');
|
|
|
|
|
std::cout << pos << std::endl;
|
|
|
|
|
std::cout << std::string::npos << std::endl;
|
|
|
|
|
std::cout << (pos != std::string::npos) << std::endl;
|
|
|
|
|
if(pos != std::string::npos) {
|
|
|
|
|
std::string postSlug = currentRoute.substr(pos + 1);
|
|
|
|
|
std::cout << postSlug << std::endl;
|
|
|
|
|
RenderBlogPost(postSlug);
|
|
|
|
|
} else {
|
2025-11-14 23:56:39 +01:00
|
|
|
main.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 {
|
|
|
|
|
RenderBlog(); //default route
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|