This commit is contained in:
Jorijn van der Graaf 2025-11-12 21:24:23 +01:00
commit 02c07ceaa2
6 changed files with 575 additions and 31 deletions

View file

@ -14,9 +14,17 @@ namespace Catcrafts {
std::string RenderBlog() {
std::string html = "";
for(const BlogPost& post : *posts) {
html += std::format("{}<br>{}<br><br>{}", post.name, post.date, post.content);
html += std::format(R"(
<div class="post fade-in">
<div class="post-header">
<h2 class="post-title">{}</h2>
<span class="post-date">{}</span>
</div>
<div class="post-content">
{}
</div>
</div>)", post.name, post.date, post.content);
}
return html;
}
}
}

View file

@ -17,33 +17,23 @@ 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
if(route == "/blog") {
pageContent = RenderBlog();
} else {
pageContent = RenderBlog(); //default route
}
// Set body content
main->SetInnerHTML(pageContent);
body->SetInnerHTML(std::format(R"(
Catcrafts.net
<nav>
<ul>
<li><a id="blog-nav-button" style="cursor: pointer;">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) {
PushState("{}", "", "/blog");
RenderRoot("blog");
});
// 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", "");
// }
//}
}
int main() {
@ -51,5 +41,11 @@ int main() {
RenderRoot(GetPathNameString());
});
blogButton = new HtmlElementView("blog-nav-button");
blogButton->AddClickListener([](Crafter::MouseEvent e) {
PushState("{}", "", "/blog");
RenderRoot("blog");
});
RenderRoot("/");
}