diff --git a/Cargo.lock b/Cargo.lock index ccf4fa6..ce0cc79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -297,7 +297,7 @@ dependencies = [ [[package]] name = "bard" -version = "0.3.12" +version = "0.3.13" dependencies = [ "dioxus", "tavern", diff --git a/bard/Cargo.toml b/bard/Cargo.toml index d3b41a1..e3e2faf 100644 --- a/bard/Cargo.toml +++ b/bard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bard" -version = "0.3.12" +version = "0.3.13" edition = "2024" description = "Dioxus components that will display a Tavern blogging system Blog." repository = "/CyberMages/tavern" diff --git a/bard/src/components/post.rs b/bard/src/components/post.rs index c7a474b..2c927f1 100644 --- a/bard/src/components/post.rs +++ b/bard/src/components/post.rs @@ -23,29 +23,55 @@ pub fn BlogAuthor() -> Element #[component] -pub fn PostHeaderAuthor(adventurer: Adventurer) -> Element +pub fn PostHeaderAuthor(author: Option) -> Element { - rsx! + match author { - document::Meta + Some(adventurer) => { - name: "author", - content: "{adventurer.name}" + rsx! + { + document::Meta + { + name: "author", + content: "{adventurer.name}" + } + + p + { + b + { + "Author: ", + a { href: "{adventurer.legend.profile}", "{adventurer.name}" } + } + } + } } - p + None=> { - b + rsx! { - "Author: ", - a { href: "{adventurer.legend.profile}", "{adventurer.name}" } + document::Meta + { + name: "author", + content: "Unknown" + } + + p + { + b + { + "Author: Unknown" + } + } } } } } #[component] -pub fn PostHeader(tale: Tale) -> Element +pub fn PostHeader(tale: Tale, adventurer: Option) -> Element { // Get the pages URL. let url: Page = use_route(); @@ -55,13 +81,6 @@ pub fn PostHeader(tale: Tale) -> Element // Retrieve the provided settings from context. let settings = use_context::(); - let author_future = use_server_future(move || - { - let handle: String = tale.lore.author.clone(); - - async move { get_author(handle).await } - })?; - rsx! { // Adding for SEO and OpenGraph post sharing. @@ -91,14 +110,7 @@ pub fn PostHeader(tale: Tale) -> Element } } - if let Some(Ok(Some(adventurer))) = (author_future.value())() - { - PostHeaderAuthor { adventurer: adventurer } - } - else - { - p { "Loading author..." } - } + PostHeaderAuthor { author: adventurer } } } @@ -125,7 +137,12 @@ pub fn BlogPost(slug: Signal, children: Element) -> Element // Make this reactive so that as the page changes it should rerun this. let url_slug = slug(); - async move { get_blog_post(url_slug).await } + async move + { + let post = get_blog_post(url_slug).await?; + let author = get_author(post.lore.author.clone()).await?; + Ok::<_, ServerFnError>((post, author)) + } })?; rsx! @@ -134,11 +151,12 @@ pub fn BlogPost(slug: Signal, children: Element) -> Element { class: "blog_post", - if let Some(Ok(tale)) = (post_future.value())() + if let Some(Ok((tale, adventurer))) = (post_future.value())() { PostHeader { - tale: tale.clone() + tale: tale.clone(), + adventurer: adventurer.clone() } Story { text: tale.story }