From c8cb2352f8629bad96179da4b2017b26cfab377c Mon Sep 17 00:00:00 2001 From: shockrah Date: Sun, 10 Nov 2019 20:23:44 -0800 Subject: [PATCH] adding support for tera templating --- website/Rocket.toml | 6 ++- website/src/main.rs | 41 ++++++++++++++-- website/static/html/index.tera | 85 ++++++++++++++++++++++++++++++++++ website/static/html/login.tera | 0 4 files changed, 128 insertions(+), 4 deletions(-) create mode 100644 website/static/html/index.tera create mode 100644 website/static/html/login.tera diff --git a/website/Rocket.toml b/website/Rocket.toml index 047520f..9380dfc 100644 --- a/website/Rocket.toml +++ b/website/Rocket.toml @@ -1,4 +1,8 @@ [development] address="localhost" port=8080 - +templates_dir="static/html/" +[production] +address="localhost" +port=8080 +templates_dir="static/html/" \ No newline at end of file diff --git a/website/src/main.rs b/website/src/main.rs index f8ffb31..0aca03b 100644 --- a/website/src/main.rs +++ b/website/src/main.rs @@ -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 { +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(); } diff --git a/website/static/html/index.tera b/website/static/html/index.tera new file mode 100644 index 0000000..75cd8df --- /dev/null +++ b/website/static/html/index.tera @@ -0,0 +1,85 @@ + + + + + + + + {{og_title}} + + + + + + + + + + + + + + + + + + + +
+
+

{{brand_url}}

+

{{brand_motto}}

+

+ {{brand_quip}} +

+
+
+ +
+
+

A chat platform that respects your privacy and freedom

+
+
+

How much?

+

Nothing. It's free to run your own instance

+
+
+

Is it hard to setup?

+

Not at all, you can easily spin up an instance using the guide here.

+
+
+
+
+ + + + + \ No newline at end of file diff --git a/website/static/html/login.tera b/website/static/html/login.tera new file mode 100644 index 0000000..e69de29