adding support for tera templating
This commit is contained in:
parent
ca6401afab
commit
c8cb2352f8
@ -1,4 +1,8 @@
|
||||
[development]
|
||||
address="localhost"
|
||||
port=8080
|
||||
|
||||
templates_dir="static/html/"
|
||||
[production]
|
||||
address="localhost"
|
||||
port=8080
|
||||
templates_dir="static/html/"
|
@ -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();
|
||||
}
|
||||
|
85
website/static/html/index.tera
Normal file
85
website/static/html/index.tera
Normal file
@ -0,0 +1,85 @@
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="title" content="{{og_title}}">
|
||||
<title>{{og_title}}</title>
|
||||
<meta name="description" content="{{og_desc}}">
|
||||
<!-- open graph things -->
|
||||
<meta property="og:title" content="{{og_title}}">
|
||||
<meta property="og:type" content="{{og_type}}">
|
||||
<meta property="og:description" content="{{og_desc}}">
|
||||
<meta property="og:url" content="{{og_url}}">
|
||||
<meta property="og:image" content="{{og_image}}">
|
||||
<link rel="shortcut icon" type="image/png" href="{{favicon}}">
|
||||
|
||||
<script src="https://kit.fontawesome.com/744f5c4640.js"></script>
|
||||
<link rel="stylesheet" href="/static/css/index.css">
|
||||
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/pure-min.css" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="https://unpkg.com/purecss@1.0.0/build/grids-responsive-min.css">
|
||||
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
|
||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-lg navbar-light bg-light">
|
||||
<a class="navbar-brand" href="/">{{brand_url}}</a>
|
||||
<button
|
||||
class="navbar-toggler dropdown"
|
||||
type="button" data-toggle="collapse"
|
||||
data-target="#nav-content"
|
||||
aria-controls="nav-content"
|
||||
aria-expanded="false"
|
||||
aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="nav-content">
|
||||
<ul class="navbar-nav">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/about">What is freechat?</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="/servers">Instances</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<div class="splash-container">
|
||||
<div class="splash">
|
||||
<h1 class="splash-head">{{brand_url}}</h1>
|
||||
<p class="splash-subhead">{{brand_motto}}</p>
|
||||
<p>
|
||||
<a href="#msgform" class="pure-button pure-button-primary">{{brand_quip}}</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="content-wrapper">
|
||||
<div class="content">
|
||||
<h2 class="content-head is-center">A chat platform that respects your privacy and freedom</h2>
|
||||
<div class="pure-g">
|
||||
<div class="l-box pure-u-1 pure-u-md-1-2 pure-u-lg-1-2">
|
||||
<h3 class="content-subhead"><i class="fas fa-dollar-sign"></i>How much?</h3>
|
||||
<p>Nothing. It's free to run your own instance</p>
|
||||
</div>
|
||||
<div class="l-box pure-u-1 pure-u-md-1-2 pure-u-lg-1-2">
|
||||
<h3 class="content-subhead"><i class="fa fa-wrench"></i>Is it hard to setup?</h3>
|
||||
<p>Not at all, you can easily spin up an instance using the guide here.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<!-- If jquery doesn't come first things like dropdown menus break -->
|
||||
<script
|
||||
src="https://code.jquery.com/jquery-3.4.1.slim.js"
|
||||
integrity="sha256-BTlTdQO9/fascB1drekrDVkaKd9PkwBymMlHOiG+qLI="
|
||||
crossorigin="anonymous"></script>
|
||||
<script
|
||||
src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
|
||||
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
|
||||
crossorigin="anonymous"></script>
|
||||
</html>
|
0
website/static/html/login.tera
Normal file
0
website/static/html/login.tera
Normal file
Loading…
Reference in New Issue
Block a user