add file size

This commit is contained in:
Yann Esposito (Yogsototh) 2019-11-13 00:36:17 +01:00
parent 32ab26c448
commit 90c072ab8c
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
4 changed files with 57 additions and 0 deletions

View file

@ -5,6 +5,8 @@ echo $rootdir
echo "Full Build"
./fullbuild.sh
echo "Update file size"
./update-file-size.sh
echo "Building RSS"
./mkrss.sh
echo "RSS Built"

View file

@ -105,6 +105,7 @@
"<div class=\"rss\"><a href=\"/rss.xml\">RSS</a>: <a href=\"https://validator.w3.org/feed/check.cgi?url=https%3A%2F%2Fher.esy.fun%2Frss.xml\">Valid RSS</a></div>"
(format "<div class=\"date\">Generated: %s</div>"
(format-time-string "%Y-%m-%d %H:%M:%S"))
"<div class=\"web-file-size\">Size: XXK (HTML: XXK, CSS: XXK, IMG: XXK)</div>"
(format (concat "<div class=\"creator\"> Generated with "
"<a href=\"https://www.gnu.org/software/emacs/\" target=\"_blank\" rel=\"noopener noreferrer\">Emacs %s</a>, "
"<a href=\"http://spacemacs.org\" target=\"_blank\" rel=\"noopener noreferrer\">Spacemacs %s</a>, "

Binary file not shown.

54
update-file-size.sh Executable file
View file

@ -0,0 +1,54 @@
#!/usr/bin/env nix-shell
#!nix-shell -i zsh
#!nix-shell -I nixpkgs="https://github.com/NixOS/nixpkgs/archive/19.09.tar.gz"
webdir="_site"
sizeof() {
stat --format="%s" "$*"
}
debug () {
# print -- $*
}
toh () {
numfmt --to=iec $*
}
tmpdir=$(mktemp -d)
for fic in $webdir/**/*.html(.); do
print -n -- "$fic "
htmlsize=$(sizeof $fic)
debug HTML: $htmlsize
xfic=$tmpdir/$fic
mkdir -p $(dirname $xfic)
hxclean $fic > $xfic
images=( $( < $xfic hxselect -i -c -s '\n' 'img::attr(src)' | sed 's/^\.\.\///' ) )
imgsize=0
nbimg=0
for i in $images; do
((nbimg++))
isize=$( sizeof ${fic:h}/$i )
debug $i '=>' $isize
(( imgsize += isize ))
done
debug IMG: $imgsize
css=( $( < $xfic hxselect -i -c -s '\n' 'link[rel=stylesheet]::attr(href)'))
csssize=0
for i in $css; do
isize=$( sizeof $webdir/$i )
debug $i '=>' $isize
(( csssize += isize ))
done
debug CSS: $csssize
total=$(( htmlsize + imgsize + csssize ))
sizeinfos=$(print -- "Size: $(toh $total) (HTML: $(toh $htmlsize), CSS: $(toh $csssize), IMG: $(toh $imgsize))")
print -- $sizeinfos
perl -pi -e 's#(<div class="web-file-size">)[^<]*(</div>)#$1'"$sizeinfos"'$2#' $fic
done
rm -rf $tmpdir