Use templates and load version information

This commit is contained in:
Valentin Brandl 2019-04-23 18:21:03 +02:00
parent 3990ea0a12
commit 33288efe82
No known key found for this signature in database
GPG Key ID: 30D341DD34118D7D
2 changed files with 26 additions and 7 deletions

View File

@ -29,13 +29,13 @@ impl ResponseError for Error {
fn error_response(&self) -> HttpResponse { fn error_response(&self) -> HttpResponse {
HttpResponse::InternalServerError() HttpResponse::InternalServerError()
.content_type("text/html") .content_type("text/html")
.body(P500) .body(P500.as_slice())
} }
fn render_response(&self) -> HttpResponse { fn render_response(&self) -> HttpResponse {
HttpResponse::InternalServerError() HttpResponse::InternalServerError()
.content_type("text/html") .content_type("text/html")
.body(P500) .body(P500.as_slice())
} }
} }

View File

@ -32,8 +32,28 @@ use std::{
}; };
use structopt::StructOpt; use structopt::StructOpt;
include!(concat!(env!("OUT_DIR"), "/templates.rs"));
const COMMIT: &str = env!("VERGEN_SHA_SHORT");
const VERSION: &str = env!("CARGO_PKG_VERSION");
lazy_static! { lazy_static! {
static ref CLIENT: reqwest::Client = reqwest::Client::new(); static ref CLIENT: reqwest::Client = reqwest::Client::new();
static ref INDEX: Vec<u8> = {
let mut buf = Vec::new();
templates::index(&mut buf, COMMIT, VERSION).unwrap();
buf
};
static ref P404: Vec<u8> = {
let mut buf = Vec::new();
templates::p404(&mut buf, COMMIT, VERSION).unwrap();
buf
};
static ref P500: Vec<u8> = {
let mut buf = Vec::new();
templates::p500(&mut buf, COMMIT, VERSION).unwrap();
buf
};
} }
struct State { struct State {
@ -41,9 +61,6 @@ struct State {
cache: String, cache: String,
} }
const INDEX: &str = include_str!("../static/index.html");
const P404: &str = include_str!("../static/404.html");
const P500: &str = include_str!("../static/500.html");
const CSS: &str = include_str!("../static/tacit-css.min.css"); const CSS: &str = include_str!("../static/tacit-css.min.css");
#[derive(StructOpt, Debug)] #[derive(StructOpt, Debug)]
@ -211,13 +228,15 @@ fn overview(_: web::Path<(String, String)>) -> HttpResponse {
#[get("/")] #[get("/")]
fn index() -> HttpResponse { fn index() -> HttpResponse {
HttpResponse::Ok().content_type("text/html").body(INDEX) HttpResponse::Ok()
.content_type("text/html")
.body(INDEX.as_slice())
} }
fn p404() -> HttpResponse { fn p404() -> HttpResponse {
HttpResponse::NotFound() HttpResponse::NotFound()
.content_type("text/html") .content_type("text/html")
.body(P404) .body(P404.as_slice())
} }
#[get("/tacit-css.min.css")] #[get("/tacit-css.min.css")]