diff --git a/config.yml b/config.yml index f151dc3..60cd55e 100644 --- a/config.yml +++ b/config.yml @@ -1,11 +1,10 @@ - projects: root: name: "Root Project" description: "Root Project" website: "https://example.com" documentation: "https://docs.example.com" - since: 1999-00-00 + since: "1999-00-00" contact: email: "mail@example.com" sub: diff --git a/src/config.rs b/src/config.rs index f783bb6..906d2a2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -15,7 +15,7 @@ pub struct Project { pub documentation: Option, pub since: Option, pub contact: Option, - pub sub: HashMap, + pub sub: Option>, } #[derive(Debug, Clone, Deserialize)] @@ -23,9 +23,21 @@ pub struct ContactInfo { pub email: Option, } +impl ContactInfo { + pub fn build(&self) -> maud::PreEscaped { + maud::html!( + @if let Some(mail) = &self.email { + h3 { "Contact:" }; + p { "Mail: "; a href=(format!("mailto:{mail}")) { (mail) }}; + } + ) + } +} + impl Config { pub fn load(path: &str) -> Self { - serde_yml::from_str(&std::fs::read_to_string(path).unwrap()).unwrap() + let content = std::fs::read_to_string(path).unwrap(); + serde_yml::from_str(&content).unwrap() } } @@ -37,12 +49,26 @@ impl Project { maud::html!( div class="card" id=(card_id) { h3 { (self.name) }; - p { "Description" }; + p { (self.description) }; + @if let Some(website) = &self.website { + p { "Website: "; a href=(website) { (website) }}; + } + @if let Some(doc) = &self.documentation { + p { "Documentation: "; a href=(doc) { (doc) }}; + } + @if let Some(since) = &self.since { + p { "Started: "; a href=(since) { (since) }}; + } + @if let Some(contact) = &self.contact { + (contact.build()) + } button class="expand-button" onclick=(format!("toggleSubcards('{subcard_id}')")) { "Expand" }; div class="subcards" id=(subcard_id) { - @for (id, prj) in &self.sub { + @if let Some(sub) = &self.sub { + @for (id, prj) in sub { (prj.build(id)) } + } }; }; ) diff --git a/src/main.rs b/src/main.rs index 995bc4e..edb0f34 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ pub fn main_page(c: &State) -> String { #[launch] async fn rocket() -> _ { let conf_path: String = std::env::args() + .skip(1) .next() .unwrap_or("./config.yml".to_string()); let conf = config::Config::load(&conf_path);