use {chrono::Datelike, std::sync::LazyLock, windmark::response::Response}; static QUOTES: LazyLock> = LazyLock::new(|| { serde_json::from_str(include_str!("../content/json/quotes.json")).unwrap() }); #[allow(unused)] #[derive(yarte::Template)] #[template(path = "main")] struct Main<'a> { pub body: &'a str, pub hits: &'a i32, pub quote: &'a str, pub commit: &'a str, pub mini_commit: &'a str, pub header_image: &'a str, pub year: i32, } pub fn success( body: &impl ToString, context: &windmark::context::RouteContext, ) -> Response { Response::success( Main { body: &body.to_string(), hits: &crate::route::hits_from(context.url.path()), quote: { use rand::prelude::SliceRandom; QUOTES.choose(&mut rand::thread_rng()).unwrap() }, commit: &format!("/tree/{}", env!("VERGEN_GIT_SHA")), mini_commit: env!("VERGEN_GIT_SHA").get(0..5).unwrap_or("UNKNOWN"), header_image: &std::env::var("HEADER_IMAGE").unwrap_or_else(|_| "https://is1-ssl.mzstatic.com/image/thumb/Music112/v4/27/8b/e1/278be12a-185e-2b65-aa68-7e7e98b140f7/859754679778_cover.jpg/316x316bb.webp".to_string()), year: chrono::Utc::now().year(), } .to_string(), ) }