From 46f9000358926bfa2fe9d5ff88655e3b17aad1bd Mon Sep 17 00:00:00 2001 From: shockrah Date: Fri, 22 Oct 2021 23:24:28 -0700 Subject: [PATCH] + Meta data and page data are now split More env vars to keep track of and doc in the landing page too -_- --- api/src/page.rs | 49 ++++++++++++++++++++++++------------ api/templates/list.html.tera | 8 +++--- 2 files changed, 37 insertions(+), 20 deletions(-) diff --git a/api/src/page.rs b/api/src/page.rs index 53a96f8..a99379d 100644 --- a/api/src/page.rs +++ b/api/src/page.rs @@ -2,35 +2,52 @@ use rocket_dyn_templates::Template; use rocket::fs::NamedFile; use std::path::{Path, PathBuf}; use std::collections::HashMap; +use std::env; +// TODO: try... literally try to reduce the number of clones that happen here + +lazy_static! { + static ref SITENAME: String = { + env::var("SITE_NAME").unwrap_or("Clippable".to_string()) + }; + static ref SITEDESC: String = { + env::var("SITE_DESC").unwrap_or("Short clips".to_string()) + }; + static ref SITEURL: String = { + env::var("SITE_URL").unwrap_or("#".to_string()) + }; +} + +fn default_map() -> HashMap<&'static str, String> { + let mut h: HashMap<&'static str, String> = HashMap::new(); + h.insert("sitetitle", SITENAME.clone()); + h.insert("sitedesc", SITEDESC.clone()); + h.insert("siteurl", SITEURL.clone()); + return h; +} #[get("/")] pub async fn home() -> Template { - let mut h: HashMap<&'static str, &'static str> = HashMap::new(); - h.insert("script_src", "index.js"); - h.insert("page", "home"); + let mut h = default_map(); + h.insert("script_src", String::from("index.js")); + h.insert("page", String::from("home")); + h.insert("title", SITENAME.clone()); return Template::render("list", &h); } #[get("/category/")] pub async fn category(cat: PathBuf) -> Template { - let mut h: HashMap<&'static str, &str> = HashMap::new(); - h.insert("script_src", "category.js"); - h.insert("page", "category"); + let mut h = default_map(); + h.insert("script_src", String::from("category.js")); + h.insert("page", String::from("category")); // Opengraph meta tags bro let cat = cat.file_name().unwrap().to_string_lossy(); - h.insert("title", &cat); - - let og_cat = format!("/category/{}", &cat); - h.insert("url", &og_cat); - - let og_desc = format!("{} clips", &cat); - h.insert("desc", &og_desc); - - let og_img = format!("/thumbnail/{}/category-thumbnail.jpg", cat); - h.insert("ogimg", &og_img); + h.insert("title", cat.to_string()); + h.insert("url", format!("/category/{}", cat)); + h.insert("desc", format!("{} clips", cat)); + h.insert("ogimg", format!("/thumbnail/{}/category-thumbnail.jpg", cat)); return Template::render("list", &h); } diff --git a/api/templates/list.html.tera b/api/templates/list.html.tera index 147b805..ce6d063 100644 --- a/api/templates/list.html.tera +++ b/api/templates/list.html.tera @@ -20,10 +20,10 @@ {% endif %} {# Otherwise we defautl to the home tags #} {% else %} - + - - + + {% endif %} @@ -32,7 +32,7 @@
-

+

{{title}}