From e4570b549e15bbf4742cbd3b80d6eb059bd19c99 Mon Sep 17 00:00:00 2001
From: Philippe Loctaux
Date: Tue, 12 Dec 2023 23:37:53 +0100
Subject: [PATCH] ability to get wallpaper from url
---
src/main.rs | 8 +++++---
src/types.rs | 4 ++++
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 7b29cc9..ea737de 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -44,12 +44,14 @@ fn not_found() -> templates::NotFound<'static> {
}
}
-#[get("/")]
-fn root() -> templates::Root<'static> {
+#[get("/?")]
+fn root(wallpaper: Option<&str>) -> templates::Root<'static> {
templates::Root {
title: "Philippe Loctaux",
year: chrono::Utc::now().year(),
- wallpaper: Wallpaper::random(),
+ wallpaper: wallpaper
+ .and_then(Wallpaper::find)
+ .or_else(Wallpaper::random),
networks: Network::new(),
jobs: Job::new(),
talks: Talk::new(),
diff --git a/src/types.rs b/src/types.rs
index 063332a..364fccc 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -58,4 +58,8 @@ impl Wallpaper {
WALLPAPERS.get(ChaCha20::new().generate_range(range))
}
+
+ pub fn find(filename: &str) -> Option<&'static &'static Wallpaper> {
+ WALLPAPERS.iter().find(|w| w.file.contains(filename))
+ }
}