]> Sergey Matveev's repositories - galgen.git/blobdiff - galgen.zsh
ExifTool is able to produce HTML
[galgen.git] / galgen.zsh
index 310f7e1228689e32612daf23bfc4999fef2b5f5a..8124fd8554016b2fa6adb7c8d77eb82b9d3a0077 100755 (executable)
@@ -1,10 +1,20 @@
 #!/usr/bin/env zsh
 # Copyright (C) 2022-2023 Sergey Matveev <stargrave@stargrave.org>
 
+set -e
+
 pagesize=${PAGESIZE:-100}
+ordering=${ORDERING:-Om}
+style=$STYLE
 
-set -e
-setopt EXTENDED_GLOB
+exifTagsOmit=(
+    ExifToolVersion
+    Directory
+    FileAccessDate
+    FileAttributes
+    FileInodeChangeDate
+    FilePermissions
+)
 
 djxl2ppm() {
     djxl $1 $1.ppm
@@ -13,14 +23,17 @@ djxl2ppm() {
     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\">&lt;&lt;&lt;</a>" >> $dst
@@ -65,9 +78,9 @@ EOF
         echo "</pre>" >> $dst
         [[ -r $img.preview.webp ]] || dwebp $img -ppm -o $img.ppm
     fi
-    echo "<hr/><pre>" >> $dst
-    exiftool -a -u -g1 $img >> $dst
-    echo "</pre>" >> $dst
+    echo "<hr/>" >> $dst
+    exiftool -escapeHTML -htmlFormat -groupHeadings \
+        --${=${(j/ --/)exifTagsOmit}} $img >> $dst
     [[ -r $img.ppm ]] && {
         pnmscale -w 100 < $img.ppm > $img.ppm.ppm
         mv $img.ppm.ppm $img.ppm
@@ -85,7 +98,7 @@ for (( p=1 ; p <= $pages ; p++ )) {
     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
@@ -103,7 +116,13 @@ EOF
         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