minify all pages

This commit is contained in:
Mylloon 2023-02-09 11:19:53 +01:00
parent c4a80e15cd
commit 00cd6405ea
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
6 changed files with 23 additions and 12 deletions

View file

@ -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;

View file

@ -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 {})
}

View file

@ -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 {})
}

View file

@ -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 {})
}

View file

@ -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
View 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()
}