diff --git a/bard/Cargo.toml b/bard/Cargo.toml index bcae8cb..6898d2d 100644 --- a/bard/Cargo.toml +++ b/bard/Cargo.toml @@ -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" diff --git a/bard/src/components.rs b/bard/src/components.rs index db2027e..4eb7508 100644 --- a/bard/src/components.rs +++ b/bard/src/components.rs @@ -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, 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" } + a { href: "/blog/Web", "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 - } - } } } } -*/ #[component] diff --git a/bard/src/lib.rs b/bard/src/lib.rs index c3c4229..63fd9b6 100644 --- a/bard/src/lib.rs +++ b/bard/src/lib.rs @@ -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::*; diff --git a/bard/src/page.rs b/bard/src/page.rs new file mode 100644 index 0000000..1a49f5a --- /dev/null +++ b/bard/src/page.rs @@ -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}, +} diff --git a/bard/src/pages.rs b/bard/src/pages.rs new file mode 100644 index 0000000..a09e767 --- /dev/null +++ b/bard/src/pages.rs @@ -0,0 +1,6 @@ +mod blog; +mod post; + + +pub use crate::pages::blog::Blog; +pub use crate::pages::post::Post; diff --git a/bard/src/pages/blog.rs b/bard/src/pages/blog.rs new file mode 100644 index 0000000..8f40ce3 --- /dev/null +++ b/bard/src/pages/blog.rs @@ -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 = 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 + } + } + } + } +} diff --git a/bard/src/pages/post.rs b/bard/src/pages/post.rs new file mode 100644 index 0000000..6ebb1c8 --- /dev/null +++ b/bard/src/pages/post.rs @@ -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 + } + } + } + } +} diff --git a/bard/src/server.rs b/bard/src/server.rs index 36b9cb4..832a17e 100644 --- a/bard/src/server.rs +++ b/bard/src/server.rs @@ -59,7 +59,7 @@ async fn get_database() -> Result<&'static Arc, ServerFnError> #[server] -pub async fn get_tags(categories: Vec) -> Result, ServerFnError> +pub async fn get_tags() -> Result, ServerFnError> { let db = get_database().await?;