aboutsummaryrefslogblamecommitdiffstats
path: root/src/main.rs
blob: 042465d65f661acd1e847be01e803b3b77a3b11a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12

                                           









                      
                       
 





                                
           


                                           

 




                                                                      
           
                                                                      
 
#![feature(proc_macro_hygiene, decl_macro)]

use askama::Template;
use rocket::{
    get,
    http::RawStr,
    routes,
    response::{
        NamedFile,
        content::Html,
    },
};
use std::path::PathBuf;

#[derive(Template)]
#[template(path = "index.html")]
struct IndexTemplate<'a> {
    year: &'a str,
}

#[get("/")]
fn index<'a>() -> Html<String> {
    let t = IndexTemplate { year: "2019" };
    Html(t.render().unwrap())
}

#[get("/<file>", rank = 99)]
fn public_file(file: &RawStr) -> Option<NamedFile> {
    NamedFile::open(PathBuf::from("public/").join(file.as_str())).ok()
}

fn main() {
    rocket::ignite().mount("/", routes![index, public_file]).launch();
}