// Basic router for that server's general website page. // All new servers come with this as a default so that use rocket_contrib::templates::Template; use rocket::response::NamedFile; use std::io; // Purely for backend purposes #[derive(Serialize)] struct PageAttrs { og_title: &'static str, og_type: &'static str, og_desc: &'static str, og_url: &'static str, og_image: &'static str, // General settings favicon: &'static str, // path to the favicon // Branding things brand_url: &'static str, // default is freechat.io - clean url of domain brand_motto: &'static str, brand_quip: &'static str } macro_rules! html { ($page:expr) => { NamedFile::open(format!("static/html/{}", $page)) } } macro_rules! css { ($style:expr) => { NamedFile::open(format!("static/css/{}", $style)) } } macro_rules! js { ($js:expr) => { NamedFile::open(format!("static/js/{}", $js)) } } fn context() -> PageAttrs { PageAttrs { og_title: "Freechat", og_type: "Decentralized Chat", og_desc: "Privacy and Freedom Respecting Chat Platform", og_url: "freechat.io", og_image: "https://images.pexels.com/photos/146071/pexels-photo-146071.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260",// recall this is meant to be a path to the favicon favicon: "https://images.pexels.com/photos/146071/pexels-photo-146071.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260", brand_url: "freechat.io", brand_motto: "Freedom respecting chat platform", brand_quip: "Join an realm", } } // Pages themselves #[get("/")] fn homepage() -> Template { // Be sure to include some kind of prompt // TODO: read this type of data from a config or provide some function/macro that // does that for us so that we don't hardcode these values in like ever Template::render("index", &context()) } // Handles logging in a user to their home instance #[get("/login")] fn login_page() -> io::Result { html!("login") } #[get("/servers")] pub fn server_info() -> Template { let context = PageAttrs{ og_title: "title", og_type: "title", og_image: "asdf", og_desc: "title", og_url: "title", favicon: "title", brand_url: "title", brand_motto: "title", brand_quip: "title", }; Template::render("servers", &context) } // General resources #[get("/static/css/")] pub fn static_css(stylesheet: String) -> io::Result { println!("{}", stylesheet); css!(stylesheet) } #[get("/static/js/")] pub fn static_js(javascript: String) -> io::Result { js!(javascript) }