+ /category page handler now fills out open graph meta data correctly

This commit is contained in:
shockrah 2021-10-12 17:37:37 -07:00
parent 3252ddd586
commit ba7cd26f3a

View File

@ -6,8 +6,6 @@ use std::collections::HashMap;
#[get("/")]
pub async fn home() -> Template {
// WARN: this is just to get the templates to behave but we're still
// doing everything the browser for the home page
let mut h: HashMap<&'static str, &'static str> = HashMap::new();
h.insert("script_src", "index.js");
h.insert("page", "home");
@ -15,21 +13,36 @@ pub async fn home() -> Template {
return Template::render("list", &h);
}
#[get("/category/<cat>")]
pub async fn category(cat: String) -> Template {
let mut h: HashMap<&'static str, &'static str> = HashMap::new();
#[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");
// 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);
return Template::render("list", &h);
}
#[get("/clip/<id>")]
pub async fn video(id: String) -> Template {
println!("id: {}", id);
return Template::render("video", &{})
}
#[get("/<file..>")]
pub async fn files(file: PathBuf) -> Option<NamedFile> {
// Used for things like javascript, css, and favicons
NamedFile::open(Path::new("static/").join(file)).await.ok()
}