This commit is contained in:
JMARyA 2024-09-16 13:16:06 +02:00
parent 14a9704249
commit e0d2a5876d
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 32 additions and 6 deletions

View file

@ -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:

View file

@ -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))
}
}
};
};
)

View file

@ -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);