more specific macro rules for html css and js in router
This commit is contained in:
parent
e1f223f233
commit
1e525e3c05
@ -27,10 +27,19 @@ struct PageAttrs {
|
|||||||
brand_quip: &'static str
|
brand_quip: &'static str
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! page {
|
macro_rules! html {
|
||||||
($type:expr, $item:expr) => {
|
($page:expr) => {
|
||||||
// TODO: verify against directory traversals
|
NamedFile::open(format!("static/html/{}", $page))
|
||||||
NamedFile::open(format!("static/{}/{}.{}", $type, $item, $type))
|
}
|
||||||
|
}
|
||||||
|
macro_rules! css {
|
||||||
|
($style:expr) => {
|
||||||
|
NamedFile::open(format!("static/css/{}", $style))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
macro_rules! js {
|
||||||
|
($js:expr) => {
|
||||||
|
NamedFile::open(format!("static/js/{}", $js))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,36 +60,46 @@ fn homepage() -> Template {
|
|||||||
favicon: "https://images.pexels.com/photos/146071/pexels-photo-146071.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=750&w=1260",
|
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_url: "freechat.io",
|
||||||
brand_motto: "Freedom respecting chat platform",
|
brand_motto: "Freedom respecting chat platform",
|
||||||
brand_quip: "asdf",
|
brand_quip: "Join an realm",
|
||||||
};
|
};
|
||||||
Template::render("index", &context)
|
Template::render("index", &context)
|
||||||
}
|
}
|
||||||
// Handles logging in a user to their home instance
|
// Handles logging in a user to their home instance
|
||||||
#[get("/login")]
|
#[get("/login")]
|
||||||
fn login_page() -> io::Result<NamedFile> {
|
fn login_page() -> io::Result<NamedFile> {
|
||||||
page!("html", "login")
|
html!("login")
|
||||||
}
|
}
|
||||||
#[get("/servers")]
|
#[get("/servers")]
|
||||||
fn server_info() -> io::Result<NamedFile> {
|
fn server_info() -> Template {
|
||||||
page!("html", "servers")
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Genearl resources
|
// General resources
|
||||||
#[get("/static/css/<stylesheet>")]
|
#[get("/static/css/<stylesheet>")]
|
||||||
fn static_css(stylesheet: String) -> io::Result<NamedFile> {
|
fn static_css(stylesheet: String) -> io::Result<NamedFile> {
|
||||||
page!("css", stylesheet)
|
println!("{}", stylesheet);
|
||||||
|
css!(stylesheet)
|
||||||
}
|
}
|
||||||
#[get("/static/js/<javascript>")]
|
#[get("/static/js/<javascript>")]
|
||||||
fn static_js(javascript: String) -> io::Result<NamedFile> {
|
fn static_js(javascript: String) -> io::Result<NamedFile> {
|
||||||
page!("js", javascript)
|
js!(javascript)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
rocket::ignite()
|
rocket::ignite()
|
||||||
.mount("/", routes![
|
.mount("/", routes![
|
||||||
homepage, login_page, server_info
|
homepage, login_page, server_info,
|
||||||
])
|
|
||||||
.mount("/static", routes![
|
|
||||||
static_css, static_js
|
static_css, static_js
|
||||||
])
|
])
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
|
Loading…
Reference in New Issue
Block a user