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 actix_web::{web, App, HttpServer};
use glob::glob; use glob::glob;
use minify_html::{minify, Cfg}; use minify_html::{minify, Cfg};
mod config; mod config;
mod template;
#[path = "routes/agreements.rs"] #[path = "routes/agreements.rs"]
mod agreements; mod agreements;

View file

@ -1,6 +1,8 @@
use actix_web::{get, HttpResponse, Responder}; use actix_web::{get, HttpResponse, Responder};
use askama::Template; use askama::Template;
use crate::template::render_html;
#[get("/")] #[get("/")]
pub async fn page() -> impl Responder { pub async fn page() -> impl Responder {
HttpResponse::Ok().body(get_page()) HttpResponse::Ok().body(get_page())
@ -11,7 +13,5 @@ pub async fn page() -> impl Responder {
struct IndexTemplate {} struct IndexTemplate {}
pub fn get_page() -> std::string::String { pub fn get_page() -> std::string::String {
let index = IndexTemplate {}; render_html(&IndexTemplate {})
index.render().unwrap()
} }

View file

@ -1,6 +1,8 @@
use actix_web::{get, HttpResponse, Responder}; use actix_web::{get, HttpResponse, Responder};
use askama::Template; use askama::Template;
use crate::template::render_html;
#[get("/networks")] #[get("/networks")]
pub async fn page() -> impl Responder { pub async fn page() -> impl Responder {
HttpResponse::Ok().body(get_page()) HttpResponse::Ok().body(get_page())
@ -11,7 +13,5 @@ pub async fn page() -> impl Responder {
struct NetworksTemplate {} struct NetworksTemplate {}
pub fn get_page() -> std::string::String { pub fn get_page() -> std::string::String {
let index = NetworksTemplate {}; render_html(&NetworksTemplate {})
index.render().unwrap()
} }

View file

@ -1,6 +1,8 @@
use actix_web::{HttpResponse, Responder}; use actix_web::{HttpResponse, Responder};
use askama::Template; use askama::Template;
use crate::template::render_html;
pub async fn page() -> impl Responder { pub async fn page() -> impl Responder {
HttpResponse::NotFound().body(get_page()) HttpResponse::NotFound().body(get_page())
} }
@ -10,7 +12,5 @@ pub async fn page() -> impl Responder {
struct Error404Template {} struct Error404Template {}
pub fn get_page() -> std::string::String { pub fn get_page() -> std::string::String {
let index = Error404Template {}; render_html(&Error404Template {})
index.render().unwrap()
} }

View file

@ -1,6 +1,8 @@
use actix_web::{get, HttpResponse, Responder}; use actix_web::{get, HttpResponse, Responder};
use askama::Template; use askama::Template;
use crate::template::render_html;
#[get("/portfolio")] #[get("/portfolio")]
pub async fn page() -> impl Responder { pub async fn page() -> impl Responder {
HttpResponse::Ok().body(get_page()) HttpResponse::Ok().body(get_page())
@ -11,7 +13,5 @@ pub async fn page() -> impl Responder {
struct PortfolioTemplate {} struct PortfolioTemplate {}
pub fn get_page() -> std::string::String { pub fn get_page() -> std::string::String {
let index = PortfolioTemplate {}; render_html(&PortfolioTemplate {})
index.render().unwrap()
} }

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