#!/usr/bin/env zsh
# Copyright (C) 2022-2023 Sergey Matveev <stargrave@stargrave.org>
-pagesize=${PAGESIZE:-100}
-
set -e
-setopt EXTENDED_GLOB
+
+pagesize=${PAGESIZE:-100}
+ordering=${ORDERING:-Om}
+style=$STYLE
djxl2ppm() {
djxl $1 $1.ppm
rm ${1}-ec1.pgm
}
-imgs=((*.jxl|*.webp~*.preview.webp)(Om))
+[[ -z $style ]] || style="<link rel=\"stylesheet\" type=\"text/css\" href=\"$style\">"
+
+setopt EXTENDED_GLOB
+imgs=((*.jxl|*.webp~*.preview.webp)($ordering))
for (( i=1 ; i <= ${#imgs} ; i++ )) {
local img=${imgs[$i]}
echo $i $img
local dst=$i.img.html
cat > $dst <<EOF
<!DOCTYPE html>
-<html><head><title>Image ${i}/${#imgs}: $img</title></head><body>
+<html><head>${style}<title>Image ${i}/${#imgs}: $img</title></head><body>
EOF
[[ $i -eq 1 ]] ||
echo "<a href=\"$(( $i - 1 )).img.html\"><<<</a>" >> $dst
local dst=$p.page.html
cat > $dst <<EOF
<!DOCTYPE html>
-<html><head><title>Page ${p}/$pages</title></head><body>
+<html><head>${style}<title>Page ${p}/$pages</title></head><body>
EOF
+ [[ $p -eq 1 ]] && [[ -r .txt ]] && {
+ echo "<pre>" >> $dst
+ cat .txt >> $dst
+ echo "</pre>" >> $dst
+ }
[[ $p -eq 1 ]] ||
echo "<a href=\"$(( $p - 1 )).page.html\"><<<</a>" >> $dst
[[ $p -eq $pages ]] ||
img=$(( ( $p - 1 ) * $pagesize + $i ))
[[ $img -le ${#imgs} ]] || break
echo "<a href=\"${img}.img.html\">" >> $dst
- echo "<img alt=\"preview ${img}\" src=\"${imgs[$img]}.preview.webp\"/></a>" >> $dst
+ alt="preview ${img}"
+ title=""
+ [[ -r ${imgs[$img]}.txt ]] && {
+ alt=`cat ${imgs[$img]}.txt`
+ title="title=\"$alt\""
+ }
+ echo "<img alt=\"$alt\" $title src=\"${imgs[$img]}.preview.webp\"/></a>" >> $dst
}
echo "</body></html>" >> $dst
echo page $p