#!/bin/bash
siteroot="../2minNoods_siteroot"
noodspp=40
mkdir -p "$siteroot/img/thumbs"
pageno=1
noodcount=1
photolist="$(mktemp --suffix='.txt')"
# html and css stolen from https://perfectmotherfuckingwebsite.com/
pageheader='''
2minNoods
2minNoods
'''
rm -v "$siteroot"/index.*.html
echo '' > "$siteroot/index.html"
ls *.jpg | sort -k2 -t'_' -r > "$photolist"
while read i; do
if [ -f "$i" ]; then
if [ ! -f "$siteroot/img/$i" ]; then
echo "Resizing $i"
convert "$i" -quality 70 -strip -auto-orient -resize "960^>" "$siteroot/img/thumbs/$i"
convert "$i" -quality 90 -strip -auto-orient -resize "2160^>" "$siteroot/img/$i"
fi
if [[ $noodcount -eq 1 ]]; then
echo "$pageheader" > "$siteroot/index.$pageno.html"
fi
echo '
'"$(basename $i .jpg)"'
' >> "$siteroot/index.$pageno.html"
((noodcount++))
if [[ $noodcount -gt $noodspp ]]; then
((pageno++))
noodcount=1
fi
fi
done < "$photolist"
for ((page=1;page<=pageno;page++)); do
htmlpagenumbers=$(
echo -n '
'
for ((link=1;link<=pageno;link++)); do
if [ $link -eq $page ]; then
echo -n "$link "
else
echo -n "$link "
fi
done
echo '
')
echo "$htmlpagenumbers" >> "$siteroot/index.$page.html"
sed -i "s%%$htmlpagenumbers%" "$siteroot/index.$page.html"
echo '' >> "$siteroot/index.$page.html"
done
echo "Searching for deleted images"
for i in $siteroot/img/*.jpg; do
pic="$(basename $i)"
if ! grep -Fxq "$pic" "$photolist"; then
rm -v "$siteroot/img/thumbs/$pic" "$siteroot/img/$pic"
fi
done
rm -v "$photolist"