From e0d2a5876d3305bb39ffc84e03a0e4c933b26aff Mon Sep 17 00:00:00 2001
From: JMARyA <jmarya@hydrar.de>
Date: Mon, 16 Sep 2024 13:16:06 +0200
Subject: [PATCH] update

---
 config.yml    |  3 +--
 src/config.rs | 34 ++++++++++++++++++++++++++++++----
 src/main.rs   |  1 +
 3 files changed, 32 insertions(+), 6 deletions(-)

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<String>,
     pub since: Option<String>,
     pub contact: Option<ContactInfo>,
-    pub sub: HashMap<String, Project>,
+    pub sub: Option<HashMap<String, Project>>,
 }
 
 #[derive(Debug, Clone, Deserialize)]
@@ -23,9 +23,21 @@ pub struct ContactInfo {
     pub email: Option<String>,
 }
 
+impl ContactInfo {
+    pub fn build(&self) -> maud::PreEscaped<String> {
+        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<Config>) -> 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);