natter/src/context/page_header.rs

42 lines
1.0 KiB
Rust
Raw Normal View History

2023-12-17 14:28:27 -05:00
use serde::Serialize;
/// The header that goes above the content of the page.
///
/// This header will be mostly the same on every page.
#[derive(Debug, Serialize)]
pub(crate) struct PageHeader {
website_title: Option<String>,
home_link: Option<String>,
nav_links: Vec<NavLink>,
}
/// A link in the top-right of the page.
#[derive(Debug, Serialize)]
#[serde(tag = "type")]
#[serde(rename = "nav_link")]
pub(crate) struct NavLink {
text: Option<String>,
url: Option<String>,
2023-12-17 14:28:27 -05:00
}
impl PageHeader {
pub(crate) fn new(
website_title: Option<String>,
home_link: Option<String>,
about_me_link: Option<String>,
) -> PageHeader {
2023-12-17 14:28:27 -05:00
PageHeader {
website_title,
home_link,
nav_links: about_me_link
.map(|url| {
vec![NavLink {
text: Some("About Me".to_owned()),
url: Some(url),
}]
})
.unwrap_or_default(),
2023-12-17 14:28:27 -05:00
}
}
}