adding support for tera templating
This commit is contained in:
@@ -1,25 +1,59 @@
|
||||
// This client code really just serves as the url router for the main website where we describe what the project is about
|
||||
#![feature(proc_macro_hygiene, decl_macro, plugin)]
|
||||
//#[macro_use] extern crate serde_derive;
|
||||
#[macro_use] extern crate serde_derive;
|
||||
#[macro_use] extern crate rocket;
|
||||
extern crate rocket_contrib;
|
||||
|
||||
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! page {
|
||||
($type:expr, $item:expr) => {
|
||||
// TODO: verify against directory traversals
|
||||
NamedFile::open(format!("staic/{}/{}", $type, $item))
|
||||
NamedFile::open(format!("static/{}/{}.{}", $type, $item, $type))
|
||||
}
|
||||
}
|
||||
|
||||
// Pages themselves
|
||||
|
||||
#[get("/")]
|
||||
fn homepage() -> io::Result<NamedFile> {
|
||||
fn homepage() -> Template {
|
||||
// Be sure to include some kind of prompt
|
||||
page!("html", "index")
|
||||
// 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: "asdf",
|
||||
};
|
||||
Template::render("index", &context)
|
||||
}
|
||||
// Handles logging in a user to their home instance
|
||||
#[get("/login")]
|
||||
@@ -49,5 +83,6 @@ fn main() {
|
||||
.mount("/static", routes![
|
||||
static_css, static_js
|
||||
])
|
||||
.attach(Template::fairing())
|
||||
.launch();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user