Adding some routing.
Moving more of the Blog pieces into the Blog library.
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "bard"
|
name = "bard"
|
||||||
version = "0.0.10"
|
version = "0.0.12"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "Dioxus components that will display a Tavern blogging system Blog."
|
description = "Dioxus components that will display a Tavern blogging system Blog."
|
||||||
repository = "/CyberMages/tavern"
|
repository = "/CyberMages/tavern"
|
||||||
|
|||||||
@ -3,6 +3,7 @@ use dioxus::prelude::*;
|
|||||||
|
|
||||||
use tavern::{Adventurer, Legend, Lore, Tale};
|
use tavern::{Adventurer, Legend, Lore, Tale};
|
||||||
|
|
||||||
|
use crate::page::Page;
|
||||||
use crate::server::*;
|
use crate::server::*;
|
||||||
|
|
||||||
|
|
||||||
@ -83,7 +84,6 @@ pub fn TagList(children: Element) -> Element
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn BlogAuthor() -> Element
|
pub fn BlogAuthor() -> Element
|
||||||
{
|
{
|
||||||
@ -133,8 +133,17 @@ pub fn BlogItem(title: String, slug: String, author: String,
|
|||||||
|
|
||||||
|
|
||||||
#[component]
|
#[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!
|
rsx!
|
||||||
{
|
{
|
||||||
document::Link { rel: "stylesheet", href: LIST_CSS }
|
document::Link { rel: "stylesheet", href: LIST_CSS }
|
||||||
@ -145,16 +154,24 @@ pub fn BlogList(children: Element) -> Element
|
|||||||
ul
|
ul
|
||||||
{
|
{
|
||||||
class: "blog_list",
|
class: "blog_list",
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[component]
|
#[component]
|
||||||
pub fn BlogNav() -> Element
|
pub fn BlogNav() -> Element
|
||||||
{
|
{
|
||||||
|
let tags = use_server_future(move ||
|
||||||
|
{
|
||||||
|
async move
|
||||||
|
{
|
||||||
|
get_tags().await
|
||||||
|
}
|
||||||
|
})?;
|
||||||
|
|
||||||
rsx!
|
rsx!
|
||||||
{
|
{
|
||||||
document::Link { rel: "stylesheet", href: NAV_CSS }
|
document::Link { rel: "stylesheet", href: NAV_CSS }
|
||||||
@ -172,44 +189,28 @@ pub fn BlogNav() -> Element
|
|||||||
li
|
li
|
||||||
{
|
{
|
||||||
class: "tag_item",
|
class: "tag_item",
|
||||||
a { href: "/blog.html", "LeetCode" }
|
a { href: "/blog/LeetCode", "LeetCode" }
|
||||||
}
|
}
|
||||||
li
|
li
|
||||||
{
|
{
|
||||||
class: "tag_item",
|
class: "tag_item",
|
||||||
a { href: "/blog.html", "Embedded" }
|
a { href: "/blog/Embedded", "Embedded" }
|
||||||
}
|
}
|
||||||
li
|
li
|
||||||
{
|
{
|
||||||
class: "tag_item",
|
class: "tag_item",
|
||||||
a { href: "/blog.html", "Simulation" }
|
a { href: "/blog/Simulation", "Simulation" }
|
||||||
}
|
}
|
||||||
li
|
li
|
||||||
{
|
{
|
||||||
class: "tag_item",
|
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]
|
#[component]
|
||||||
|
|||||||
@ -3,7 +3,8 @@
|
|||||||
mod info;
|
mod info;
|
||||||
|
|
||||||
mod components;
|
mod components;
|
||||||
|
mod page;
|
||||||
|
mod pages;
|
||||||
mod server;
|
mod server;
|
||||||
|
|
||||||
|
|
||||||
@ -11,6 +12,8 @@ mod server;
|
|||||||
pub use crate::info::{get_name, get_version};
|
pub use crate::info::{get_name, get_version};
|
||||||
|
|
||||||
pub use crate::components::*;
|
pub use crate::components::*;
|
||||||
|
pub use crate::page::Page;
|
||||||
|
pub use crate::pages::*;
|
||||||
|
|
||||||
#[cfg(feature = "server")]
|
#[cfg(feature = "server")]
|
||||||
pub use crate::server::*;
|
pub use crate::server::*;
|
||||||
|
|||||||
16
bard/src/page.rs
Normal file
16
bard/src/page.rs
Normal 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
6
bard/src/pages.rs
Normal 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
41
bard/src/pages/blog.rs
Normal 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
33
bard/src/pages/post.rs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -59,7 +59,7 @@ async fn get_database() -> Result<&'static Arc<Database>, ServerFnError>
|
|||||||
|
|
||||||
|
|
||||||
#[server]
|
#[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?;
|
let db = get_database().await?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user