From b2f7640b29c2634c44abae548941f8eae3ce8287 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Tue, 17 Sep 2024 07:32:49 +0200 Subject: [PATCH] add icons --- docker-compose.yml | 1 + src/config.rs | 4 ++++ src/main.rs | 13 ++++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index c890eec..85f9a50 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,5 +6,6 @@ services: - "8000:8000" volumes: - ./config.yml:/config.yml + - ./icons:/static/icons environment: ROCKET_ADDRESS: 0.0.0.0 diff --git a/src/config.rs b/src/config.rs index 6e78ab6..17939b4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -11,6 +11,7 @@ pub struct Config { pub struct Project { pub name: String, pub description: String, + pub icon: Option, pub website: Option, pub documentation: Option, pub since: Option, @@ -47,6 +48,9 @@ impl Project { maud::html!( div class="card" id=(card_id) { + @if let Some(icon) = &self.icon { + img src=(format!("/static/icons/{}", icon)) style="float: left; width: 200px; height: 200px;"; + } h3 { (self.name) }; p { (self.description) }; @if let Some(website) = &self.website { diff --git a/src/main.rs b/src/main.rs index 1faac3b..9db7966 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,19 @@ +use std::path::Path; + use config::Config; +use rocket::fs::NamedFile; use rocket::response::content::RawHtml; use rocket::{get, launch, routes, State}; mod config; mod site; +#[get("/icon/")] +async fn icon_res(file: &str) -> Option { + let path = Path::new("static/icons/").join(file); + NamedFile::open(path).await.ok() +} + #[get("/")] pub fn main_page(c: &State) -> RawHtml { RawHtml(site::gen_site(c)) @@ -18,5 +27,7 @@ async fn rocket() -> _ { .unwrap_or("./config.yml".to_string()); let conf = config::Config::load(&conf_path); - rocket::build().mount("/", routes![main_page]).manage(conf) + rocket::build() + .mount("/", routes![main_page, icon_res]) + .manage(conf) }