This repository has been archived on 2022-05-01. You can view files and clone it, but cannot push or open issues or pull requests.
www/scripts_nohugo/outils/html-minifier.bash

46 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
set -e
#set -x
clear
########################################################################
###
##
#
# Author: Stéphane HUC
# mail: devs@stephane-huc.net
# gpg:fingerprint: CE2C CF7C AB68 0329 0D20 5F49 6135 D440 4D44 BD58
#
# License: Public Domain
#
# Git:
#
# Date: 2020/05/10
#
##
###
########################################################################
ROOT="$(dirname "$(readlink -f -- "$0")")"
minifier="/usr/bin/java -jar $ROOT/htmlcompressor-1.5.3.jar"
########################################################################
printf '%s\n' "Write a root folder where files HTML exist: "
read -r dir
#dir="$1"
# if dir end with /, substring this
if [ "${dir: -1}" = '/' ]; then dir="${dir:0:-1}"; fi
mindir="${dir}.min"
#echo "dir: $dir"
declare -a exts=(html xml)
if [ ! -d "${dir}" ]; then printf '%s\n' "[ KO ] The script '$0' stop, because the dir '${dir}' not exists!"; exit; fi
if [ ! -d "${mindir}" ]; then mkdir "${mindir}"; fi
#echo "dir: $dir"
for ext in "${exts[@]}"; do
$minifier --recursive --type "${ext}" -o $mindir $dir
done