add photo source variable to make non-interactive running of the script easier
This commit is contained in:
59
2minNoods.sh
59
2minNoods.sh
@@ -3,15 +3,26 @@
|
||||
# Dependencies: mktemp, sed, imagemagick, basename, grep, sort
|
||||
|
||||
# Config variables
|
||||
siteroot="../2minNoods_siteroot"
|
||||
# 'siteroot' is where the html and compressed images are stored
|
||||
siteroot='../2minNoods_siteroot'
|
||||
|
||||
# 'picsource' is the directory where all the photos are stored. If unset it will default to the the current working directory.
|
||||
picsource=''
|
||||
|
||||
# 'noodspp' are the number of images that will be displayed on each page
|
||||
noodspp=40
|
||||
|
||||
|
||||
# Don't touch these
|
||||
pageno=1
|
||||
noodcount=1
|
||||
photolist="$(mktemp --suffix='.txt')"
|
||||
mkdir -p "$siteroot/img/thumbs"
|
||||
|
||||
if [ -z "$picsource" ]; then
|
||||
picsource='.'
|
||||
fi
|
||||
|
||||
# html and css stolen from: https://perfectmotherfuckingwebsite.com/
|
||||
# a.button stolen from: https://stackoverflow.com/a/2906586
|
||||
pageheader='''<!DOCTYPE html>
|
||||
@@ -68,26 +79,32 @@ rm -v "$siteroot"/index.*.html
|
||||
|
||||
echo '<meta http-equiv="refresh" content="0; url=index.1.html" />' > "$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 '<h3>'"$(basename $i .jpg)"'</h3><a href="'"img/$i"'"><img src="'"img/thumbs/$i"'" style="width:100%" loading="lazy"></a><hr>' >> "$siteroot/index.$pageno.html"
|
||||
((noodcount++))
|
||||
if [[ $noodcount -gt $noodspp ]]; then
|
||||
((pageno++))
|
||||
noodcount=1
|
||||
fi
|
||||
for img in "$picsource"/*.jpg; do
|
||||
if [ -f "$img" ]; then
|
||||
basename "$img" >> "$photolist"
|
||||
fi
|
||||
done < "$photolist"
|
||||
done
|
||||
|
||||
sort -k2 -t'_' -r "$photolist" > "$photolist.sorted"
|
||||
|
||||
#ls "$picsource"/*.jpg | sort -k2 -t'_' -r > "$photolist"
|
||||
|
||||
while read img; do
|
||||
if [ ! -f "$siteroot/img/$img" ]; then
|
||||
echo "Resizing $img"
|
||||
convert "$picsource/$img" -quality 70 -strip -auto-orient -resize "960^>" "$siteroot/img/thumbs/$img"
|
||||
convert "$picsource/$img" -quality 90 -strip -auto-orient -resize "2160^>" "$siteroot/img/$img"
|
||||
fi
|
||||
if [[ $noodcount -eq 1 ]]; then
|
||||
echo "$pageheader" > "$siteroot/index.$pageno.html"
|
||||
fi
|
||||
echo '<h3>'"$(basename $img .jpg)"'</h3><a href="'"img/$img"'"><img src="'"img/thumbs/$img"'" style="width:100%" loading="lazy"></a><hr>' >> "$siteroot/index.$pageno.html"
|
||||
((noodcount++))
|
||||
if [[ $noodcount -gt $noodspp ]]; then
|
||||
((pageno++))
|
||||
noodcount=1
|
||||
fi
|
||||
done < "$photolist.sorted"
|
||||
|
||||
for ((page=1;page<=pageno;page++)); do
|
||||
htmlpagenumbers=$(
|
||||
@@ -114,4 +131,4 @@ for i in $siteroot/img/*.jpg; do
|
||||
fi
|
||||
done
|
||||
|
||||
rm -v "$photolist"
|
||||
rm -v "$photolist" "$photolist.sorted"
|
||||
|
||||
Reference in New Issue
Block a user