minify all pages
This commit is contained in:
parent
c4a80e15cd
commit
00cd6405ea
6 changed files with 23 additions and 12 deletions
|
@ -8,7 +8,9 @@ use actix_files::Files;
|
|||
use actix_web::{web, App, HttpServer};
|
||||
use glob::glob;
|
||||
use minify_html::{minify, Cfg};
|
||||
|
||||
mod config;
|
||||
mod template;
|
||||
|
||||
#[path = "routes/agreements.rs"]
|
||||
mod agreements;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use actix_web::{get, HttpResponse, Responder};
|
||||
use askama::Template;
|
||||
|
||||
use crate::template::render_html;
|
||||
|
||||
#[get("/")]
|
||||
pub async fn page() -> impl Responder {
|
||||
HttpResponse::Ok().body(get_page())
|
||||
|
@ -11,7 +13,5 @@ pub async fn page() -> impl Responder {
|
|||
struct IndexTemplate {}
|
||||
|
||||
pub fn get_page() -> std::string::String {
|
||||
let index = IndexTemplate {};
|
||||
|
||||
index.render().unwrap()
|
||||
render_html(&IndexTemplate {})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use actix_web::{get, HttpResponse, Responder};
|
||||
use askama::Template;
|
||||
|
||||
use crate::template::render_html;
|
||||
|
||||
#[get("/networks")]
|
||||
pub async fn page() -> impl Responder {
|
||||
HttpResponse::Ok().body(get_page())
|
||||
|
@ -11,7 +13,5 @@ pub async fn page() -> impl Responder {
|
|||
struct NetworksTemplate {}
|
||||
|
||||
pub fn get_page() -> std::string::String {
|
||||
let index = NetworksTemplate {};
|
||||
|
||||
index.render().unwrap()
|
||||
render_html(&NetworksTemplate {})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use actix_web::{HttpResponse, Responder};
|
||||
use askama::Template;
|
||||
|
||||
use crate::template::render_html;
|
||||
|
||||
pub async fn page() -> impl Responder {
|
||||
HttpResponse::NotFound().body(get_page())
|
||||
}
|
||||
|
@ -10,7 +12,5 @@ pub async fn page() -> impl Responder {
|
|||
struct Error404Template {}
|
||||
|
||||
pub fn get_page() -> std::string::String {
|
||||
let index = Error404Template {};
|
||||
|
||||
index.render().unwrap()
|
||||
render_html(&Error404Template {})
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
use actix_web::{get, HttpResponse, Responder};
|
||||
use askama::Template;
|
||||
|
||||
use crate::template::render_html;
|
||||
|
||||
#[get("/portfolio")]
|
||||
pub async fn page() -> impl Responder {
|
||||
HttpResponse::Ok().body(get_page())
|
||||
|
@ -11,7 +13,5 @@ pub async fn page() -> impl Responder {
|
|||
struct PortfolioTemplate {}
|
||||
|
||||
pub fn get_page() -> std::string::String {
|
||||
let index = PortfolioTemplate {};
|
||||
|
||||
index.render().unwrap()
|
||||
render_html(&PortfolioTemplate {})
|
||||
}
|
||||
|
|
9
src/template.rs
Normal file
9
src/template.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
use askama::DynTemplate;
|
||||
use minify_html::{minify, Cfg};
|
||||
|
||||
pub fn render_html(template: &dyn DynTemplate) -> String {
|
||||
let data = template.dyn_render().unwrap();
|
||||
|
||||
let cfg = Cfg::spec_compliant();
|
||||
String::from_utf8(minify(data.as_bytes(), &cfg)).unwrap()
|
||||
}
|
Loading…
Reference in a new issue