feat: minification #17

Merged
Anri merged 14 commits from minification into main 2023-04-09 19:30:04 +02:00
Showing only changes of commit c42238a624 - Show all commits

View file

@ -89,8 +89,10 @@ pub fn get_config(file_path: &str) -> Config {
let internal_config = get_file_config(file_path);
let static_dir = "static".to_string();
// TODO: Check if templates dir is coherent with the whole list
let templates_dir = get_askama_config().general.dirs.last().unwrap().to_string();
let files_root = init(static_dir.clone(), templates_dir);
// TODO: Check dist by askama config file
let files_root = init("dist".to_string(), static_dir.clone(), templates_dir);
Config {
fc: internal_config,
@ -98,16 +100,11 @@ pub fn get_config(file_path: &str) -> Config {
}
}
fn init(static_dir: String, templates_dir: String) -> String {
let dist_folder = "dist".to_string();
// println!("static = {}/{}", dist_folder, static_dir);
// println!("templates = {}/{}", dist_folder, templates_dir);
fn init(dist_dir: String, static_dir: String, templates_dir: String) -> String {
// The static folder is minimized only in release mode
if cfg!(debug_assertions) {
// Be sure that we not gonna use the dist folder by deleting it
remove_dir_all(dist_folder).unwrap_or_default();
remove_dir_all(dist_dir).unwrap_or_default();
".".to_string()
} else {
@ -118,7 +115,7 @@ fn init(static_dir: String, templates_dir: String) -> String {
let path = entry.unwrap();
let path_with_dist = path
.to_string_lossy()
.replace(&static_dir, &format!("{dist_folder}/{static_dir}"));
.replace(&static_dir, &format!("{dist_dir}/{static_dir}"));
minify_and_copy(&cfg, path, path_with_dist);
}
@ -128,12 +125,12 @@ fn init(static_dir: String, templates_dir: String) -> String {
let path = entry.unwrap();
let path_with_dist = path
.to_string_lossy()
.replace(&templates_dir, &format!("{dist_folder}/{templates_dir}"));
.replace(&templates_dir, &format!("{dist_dir}/{templates_dir}"));
minify_and_copy(&cfg, path, path_with_dist);
}
dist_folder
dist_dir
}
}