diff --git a/src/gen-wallpapers.rs b/src/gen-wallpapers.rs index 763338e..046ff44 100644 --- a/src/gen-wallpapers.rs +++ b/src/gen-wallpapers.rs @@ -7,7 +7,7 @@ use std::path::PathBuf; const WALLPAPERS_PATH: &str = "/public/wallpapers"; const CRATE_PATH: &str = env!("CARGO_MANIFEST_DIR"); -const IMPORTS: &str = r#"use crate::types::{Location,Wallpaper};"#; +const IMPORTS: &str = r#"use crate::types::{Gps, Location, Wallpaper};"#; #[derive(Debug)] struct Metadata { @@ -185,8 +185,19 @@ fn main() { println!("Precise location is `{}`", precise); println!("Broad location is `{}`", broad); - // Construct struct - let wallpaper_struct = format!("&Wallpaper {{ file: \"{}\", date: \"{}\", location: Location {{ precise: \"{}\", broad: \"{}\", latitude: {}, longitude: {} }} }},\n", wallpaper.file, wallpaper.date, precise, broad, wallpaper.latitude, wallpaper.longitude); + // Construct structs + let gps_struct = format!( + "Gps {{ latitude: {}, longitude: {} }}", + wallpaper.latitude, wallpaper.longitude + ); + let location_struct = format!( + "Location {{ precise: \"{}\", broad: \"{}\", gps: {} }}", + precise, broad, gps_struct + ); + let wallpaper_struct = format!( + "&Wallpaper {{ file: \"{}\", date: \"{}\", location: {} }},\n", + wallpaper.file, wallpaper.date, location_struct + ); wallpapers.push_str(&wallpaper_struct); } diff --git a/src/main.rs b/src/main.rs index 967cd60..7b29cc9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,22 +12,28 @@ mod wallpapers; #[launch] fn rocket() -> _ { - rocket::build() + let server = rocket::build() .mount("/", FileServer::from("public")) - .mount("/", routes![root, email]) - .register("/", catchers![not_found]) - .attach( - rocket_async_compression::CachedCompression::path_suffix_fairing(vec![ - // Code - ".js".into(), - ".css".into(), - // Documents - ".pdf".into(), - ".txt".into(), - ]), - ) - .attach(cache::CacheControl::default()) - .attach(minify::Minify) + .mount("/", routes![root, email, wallpapers_route]) + .register("/", catchers![not_found]); + + if cfg!(debug_assertions) { + server + } else { + server + .attach( + rocket_async_compression::CachedCompression::path_suffix_fairing(vec![ + // Code + ".js".into(), + ".css".into(), + // Documents + ".pdf".into(), + ".txt".into(), + ]), + ) + .attach(cache::CacheControl::default()) + .attach(minify::Minify) + } } #[catch(404)] @@ -59,3 +65,12 @@ fn email() -> templates::Email<'static> { year: chrono::Utc::now().year(), } } + +#[get("/wallpapers")] +fn wallpapers_route() -> templates::Wallpapers<'static> { + templates::Wallpapers { + title: "Wallpapers", + year: chrono::Utc::now().year(), + wallpapers: WALLPAPERS, + } +} diff --git a/src/templates.rs b/src/templates.rs index 7037d31..18265bd 100644 --- a/src/templates.rs +++ b/src/templates.rs @@ -1,8 +1,7 @@ use crate::filters; use crate::types::*; -use askama::Template; -#[derive(Template)] +#[derive(askama::Template)] #[template(path = "pages/root.html")] pub struct Root<'a> { pub title: &'a str, @@ -20,7 +19,7 @@ struct RootResponder<'a> { template: Root<'a>, } -#[derive(Template)] +#[derive(askama::Template)] #[template(path = "pages/404.html")] pub struct NotFound<'a> { pub title: &'a str, @@ -32,7 +31,7 @@ struct NotFoundResponder<'a> { template: NotFound<'a>, } -#[derive(Template)] +#[derive(askama::Template)] #[template(path = "pages/email.html")] pub struct Email<'a> { pub title: &'a str, @@ -43,3 +42,16 @@ pub struct Email<'a> { struct EmailResponder<'a> { template: Email<'a>, } + +#[derive(askama::Template)] +#[template(path = "pages/wallpapers.html")] +pub struct Wallpapers<'a> { + pub title: &'a str, + pub year: i32, + pub wallpapers: &'static [&'static Wallpaper], +} + +#[derive(rocket::Responder)] +struct WallpapersResponder<'a> { + template: Wallpapers<'a>, +} diff --git a/src/types.rs b/src/types.rs index 3ad3f7d..063332a 100644 --- a/src/types.rs +++ b/src/types.rs @@ -26,9 +26,20 @@ pub struct Link { pub struct Location { pub precise: &'static str, pub broad: &'static str, + pub gps: Gps, +} + +pub struct Gps { pub latitude: f32, pub longitude: f32, } + +impl std::fmt::Display for Gps { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "[{}, {}]", self.latitude, self.longitude) + } +} + pub struct Wallpaper { pub file: &'static str, pub date: &'static str, diff --git a/tailwind.config.cjs b/tailwind.config.cjs index 21147f8..9836a4e 100644 --- a/tailwind.config.cjs +++ b/tailwind.config.cjs @@ -7,6 +7,7 @@ module.exports = { extend: { height: { almostscreen: '90vh', + halfscreen: '60vh', } }, }, diff --git a/templates/pages/wallpapers.html b/templates/pages/wallpapers.html new file mode 100644 index 0000000..4609e28 --- /dev/null +++ b/templates/pages/wallpapers.html @@ -0,0 +1,27 @@ +{% extends "content.html" %} + +{% block content %} +
Pictures I took around the world
+ + + + + + + + +{% for wallpaper in wallpapers %} + +{% endfor %} +{% endblock %}