Here we use a context provider on the app itself to handle passing the settings to our library. This way even the layout can use them.
69 lines
1.3 KiB
Rust
69 lines
1.3 KiB
Rust
use dioxus::prelude::*;
|
|
|
|
use crate::pages::{Blog, Post, Root};
|
|
use crate::settings::{BardSettings, StylesheetBehavior};
|
|
|
|
|
|
|
|
const BLOG_CSS: Asset = asset!("/assets/css/blog.css");
|
|
|
|
|
|
|
|
#[component]
|
|
fn BlogLayout() -> Element
|
|
{
|
|
// Retrieve the provided settings from context.
|
|
let settings = use_context::<BardSettings>();
|
|
|
|
rsx!
|
|
{
|
|
match settings.stylesheet
|
|
{
|
|
StylesheetBehavior::Override(asset) =>
|
|
{
|
|
rsx!
|
|
{
|
|
document::Stylesheet { href: asset }
|
|
}
|
|
}
|
|
|
|
StylesheetBehavior::Extend(asset) =>
|
|
{
|
|
rsx!
|
|
{
|
|
document::Stylesheet { href: BLOG_CSS }
|
|
document::Stylesheet { href: asset }
|
|
}
|
|
}
|
|
|
|
StylesheetBehavior::None =>
|
|
{
|
|
rsx!
|
|
{
|
|
document::Stylesheet { href: BLOG_CSS }
|
|
}
|
|
}
|
|
}
|
|
|
|
Outlet::<Page> {}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//#[derive(Debug, Clone, Routable, PartialEq, Eq, Hash, Debug, serde::Serialize, serde::Deserialize)]
|
|
#[derive(Debug, Clone, Routable, PartialEq)]
|
|
#[rustfmt::skip]
|
|
pub enum Page
|
|
{
|
|
#[layout(BlogLayout)]
|
|
#[route("/")]
|
|
Root { },
|
|
|
|
#[route("/:tag")]
|
|
Blog { tag: String },
|
|
|
|
#[route("/post/:slug")]
|
|
Post { slug: String},
|
|
}
|