Adding some routing.

Moving more of the Blog pieces into the Blog library.
This commit is contained in:
2025-09-08 10:01:02 -04:00
parent 72e35cb6dc
commit 9db5a5ea3d
8 changed files with 126 additions and 26 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "bard"
version = "0.0.10"
version = "0.0.12"
edition = "2024"
description = "Dioxus components that will display a Tavern blogging system Blog."
repository = "/CyberMages/tavern"

View File

@ -3,6 +3,7 @@ use dioxus::prelude::*;
use tavern::{Adventurer, Legend, Lore, Tale};
use crate::page::Page;
use crate::server::*;
@ -83,7 +84,6 @@ pub fn TagList(children: Element) -> Element
}
/*
#[component]
pub fn BlogAuthor() -> Element
{
@ -133,8 +133,17 @@ pub fn BlogItem(title: String, slug: String, author: String,
#[component]
pub fn BlogList(children: Element) -> Element
pub fn BlogList(tags: Vec<String>, children: Element) -> Element
{
let summaries = use_server_future(move ||
{
let categories = tags.clone();
async move
{
get_blog_list(categories).await
}
})?;
rsx!
{
document::Link { rel: "stylesheet", href: LIST_CSS }
@ -145,16 +154,24 @@ pub fn BlogList(children: Element) -> Element
ul
{
class: "blog_list",
{children}
}
}
}
}
#[component]
pub fn BlogNav() -> Element
{
let tags = use_server_future(move ||
{
async move
{
get_tags().await
}
})?;
rsx!
{
document::Link { rel: "stylesheet", href: NAV_CSS }
@ -172,44 +189,28 @@ pub fn BlogNav() -> Element
li
{
class: "tag_item",
a { href: "/blog.html", "LeetCode" }
a { href: "/blog/LeetCode", "LeetCode" }
}
li
{
class: "tag_item",
a { href: "/blog.html", "Embedded" }
a { href: "/blog/Embedded", "Embedded" }
}
li
{
class: "tag_item",
a { href: "/blog.html", "Simulation" }
a { href: "/blog/Simulation", "Simulation" }
}
li
{
class: "tag_item",
a { href: "/blog.html", "Web" }
}
}
}
SocialButtonList
{
SocialButton
{
link: String::from("https://www.linkedin.com/company/cybermages-llc"),
company: Company::LinkedIn,
size: Size::Small
}
SocialButton
{
link: String::from("https://bsky.app/profile/cybermages.tech"),
company: Company::Bluesky,
size: Size::Small
a { href: "/blog/Web", "Web" }
}
}
}
}
}
}
*/
#[component]

View File

@ -3,7 +3,8 @@
mod info;
mod components;
mod page;
mod pages;
mod server;
@ -11,6 +12,8 @@ mod server;
pub use crate::info::{get_name, get_version};
pub use crate::components::*;
pub use crate::page::Page;
pub use crate::pages::*;
#[cfg(feature = "server")]
pub use crate::server::*;

16
bard/src/page.rs Normal file
View File

@ -0,0 +1,16 @@
use dioxus::prelude::*;
use crate::pages::{Blog, Post};
#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
pub enum Page
{
#[route("/blog/:tag")]
Blog { tag: String },
#[route("/blog/post/:slug")]
Post { slug: String},
}

6
bard/src/pages.rs Normal file
View File

@ -0,0 +1,6 @@
mod blog;
mod post;
pub use crate::pages::blog::Blog;
pub use crate::pages::post::Post;

41
bard/src/pages/blog.rs Normal file
View File

@ -0,0 +1,41 @@
use dioxus::prelude::*;
use crate::page::Page;
use crate::components::BlogList;
const BLOG_CSS: Asset = asset!("/assets/css/blog.css");
/// Blog page
#[component]
pub fn Blog(tag: String) -> Element
{
let mut categories: Vec<String> = vec![];
if !tag.is_empty()
{
categories.push(tag);
}
rsx!
{
document::Stylesheet { href: BLOG_CSS }
main
{
class: "blog_style",
div
{
class: "page_content",
BlogList
{
tags: categories
}
}
}
}
}

33
bard/src/pages/post.rs Normal file
View File

@ -0,0 +1,33 @@
use dioxus::prelude::*;
use crate::page::Page;
use crate::components::BlogPost;
const BLOG_CSS: Asset = asset!("/assets/css/blog.css");
/// Blog page
#[component]
pub fn Post(slug: String) -> Element
{
rsx!
{
document::Stylesheet { href: BLOG_CSS }
main
{
class: "blog_style",
div
{
class: "page_content",
BlogPost
{
slug: slug
}
}
}
}
}

View File

@ -59,7 +59,7 @@ async fn get_database() -> Result<&'static Arc<Database>, ServerFnError>
#[server]
pub async fn get_tags(categories: Vec<String>) -> Result<Vec<String>, ServerFnError>
pub async fn get_tags() -> Result<Vec<String>, ServerFnError>
{
let db = get_database().await?;