ability to get wallpaper from url

This commit is contained in:
Philippe Loctaux 2023-12-12 23:37:53 +01:00
parent 5e434a37ed
commit e4570b549e
2 changed files with 9 additions and 3 deletions

View file

@ -44,12 +44,14 @@ fn not_found() -> templates::NotFound<'static> {
} }
} }
#[get("/")] #[get("/?<wallpaper>")]
fn root() -> templates::Root<'static> { fn root(wallpaper: Option<&str>) -> templates::Root<'static> {
templates::Root { templates::Root {
title: "Philippe Loctaux", title: "Philippe Loctaux",
year: chrono::Utc::now().year(), year: chrono::Utc::now().year(),
wallpaper: Wallpaper::random(), wallpaper: wallpaper
.and_then(Wallpaper::find)
.or_else(Wallpaper::random),
networks: Network::new(), networks: Network::new(),
jobs: Job::new(), jobs: Job::new(),
talks: Talk::new(), talks: Talk::new(),

View file

@ -58,4 +58,8 @@ impl Wallpaper {
WALLPAPERS.get(ChaCha20::new().generate_range(range)) WALLPAPERS.get(ChaCha20::new().generate_range(range))
} }
pub fn find(filename: &str) -> Option<&'static &'static Wallpaper> {
WALLPAPERS.iter().find(|w| w.file.contains(filename))
}
} }