+ Meta data and page data are now split
More env vars to keep track of and doc in the landing page too -_-
This commit is contained in:
@@ -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/<cat..>")]
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user