catcrafts.net/implementations/main.cpp

51 lines
1.3 KiB
C++
Raw Normal View History

2025-11-12 20:58:07 +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.
*/
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;
2025-11-12 21:24:23 +01:00
if(route == "/blog") {
2025-11-12 20:58:07 +01:00
pageContent = RenderBlog();
} else {
pageContent = RenderBlog(); //default route
}
2025-11-12 21:24:23 +01:00
// Set body content
main->SetInnerHTML(pageContent);
// Update active nav link
// auto navLinks = document->GetElementsByClassName("nav-container")[0]->GetElementsByTagName("a");
// for(auto link : navLinks) {
// if(link->GetAttribute("id") == "blog-nav-button") {
// link->SetAttribute("class", "active");
// } else {
// link->SetAttribute("class", "");
// }
//}
}
2025-11-12 20:58:07 +01:00
2025-11-12 21:24:23 +01:00
int main() {
AddPopStateListener([]() {
RenderRoot(GetPathNameString());
});
2025-11-12 20:58:07 +01:00
blogButton = new HtmlElementView("blog-nav-button");
blogButton->AddClickListener([](Crafter::MouseEvent e) {
PushState("{}", "", "/blog");
RenderRoot("blog");
});
RenderRoot("/");
}