56 lines
1.4 KiB
C++
56 lines
1.4 KiB
C++
|
|
/*
|
||
|
|
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;
|
||
|
|
if(route == "/blog") { //currently pointless if but for adding more pages in the future
|
||
|
|
pageContent = RenderBlog();
|
||
|
|
} else {
|
||
|
|
pageContent = RenderBlog(); //default route
|
||
|
|
}
|
||
|
|
|
||
|
|
body->SetInnerHTML(std::format(R"(
|
||
|
|
Catcrafts.net
|
||
|
|
<nav>
|
||
|
|
<ul>
|
||
|
|
<li><a id="blog-nav-button">Blog</a></li>
|
||
|
|
<li><a href="https://forgejo.catcrafts.net/">Forgejo</a></li>
|
||
|
|
</ul>
|
||
|
|
</nav>
|
||
|
|
|
||
|
|
{}
|
||
|
|
|
||
|
|
<footer>Powered by Crafter.CppDOM, Running near native with WASM!, <a href="https://forgejo.catcrafts.net/Catcrafts/catcrafts.net">View source</a></footer>)", pageContent));
|
||
|
|
|
||
|
|
if(blogButton) {
|
||
|
|
delete blogButton;
|
||
|
|
}
|
||
|
|
blogButton = new HtmlElementView("blog-nav-button");
|
||
|
|
blogButton->AddClickListener([](Crafter::MouseEvent e) {
|
||
|
|
std::cout << "click" << std::endl;
|
||
|
|
PushState("{}", "", "/blog");
|
||
|
|
RenderRoot("blog");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
AddPopStateListener([]() {
|
||
|
|
RenderRoot(GetPathNameString());
|
||
|
|
});
|
||
|
|
|
||
|
|
RenderRoot("/");
|
||
|
|
}
|