diff --git a/server/src/main.rs b/server/src/main.rs index 345c099..463333a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -6,8 +6,8 @@ extern crate rocket_contrib; use rocket_contrib::templates::Template; -use rocket::response::NamedFile; -use std::io; +mod website; +use website::*; // Purely for backend purposes #[derive(Serialize)] @@ -27,74 +27,6 @@ struct PageAttrs { 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)) - } -} - -// 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 - let context = 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", - }; - Template::render("index", &context) -} -// Handles logging in a user to their home instance -#[get("/login")] -fn login_page() -> io::Result { - html!("login") -} -#[get("/servers")] -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/")] -fn static_css(stylesheet: String) -> io::Result { - println!("{}", stylesheet); - css!(stylesheet) -} -#[get("/static/js/")] -fn static_js(javascript: String) -> io::Result { - js!(javascript) -} fn main() { rocket::ignite() diff --git a/server/src/website.rs b/server/src/website.rs index 2418a9b..ea3040f 100644 --- a/server/src/website.rs +++ b/server/src/website.rs @@ -22,21 +22,6 @@ struct PageAttrs { 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 { @@ -56,40 +41,29 @@ fn context() -> PageAttrs { // 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()) +pub fn homepage() -> Template { + let ctx = context(); + Template::render("index", &ctx) } // Handles logging in a user to their home instance #[get("/login")] -fn login_page() -> io::Result { - html!("login") +pub fn login_page() -> Template { + let ctx = context(); + Template::render("login", &ctx) } #[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) + let ctx = context(); + Template::render("servers", &ctx) } // General resources #[get("/static/css/")] pub fn static_css(stylesheet: String) -> io::Result { println!("{}", stylesheet); - css!(stylesheet) + NamedFile::open(format!("static/css/{}", stylesheet)) } #[get("/static/js/")] pub fn static_js(javascript: String) -> io::Result { - js!(javascript) + NamedFile::open(format!("static/js/{}", javascript)) }