49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
use rocket_dyn_templates::Template;
|
|
use rocket::fs::NamedFile;
|
|
use std::path::{Path, PathBuf};
|
|
use std::collections::HashMap;
|
|
|
|
|
|
#[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");
|
|
|
|
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");
|
|
|
|
// 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()
|
|
}
|