]> Sergey Matveev's repositories - galgen.git/blobdiff - galgen.zsh
Ability to specify link to the stylesheet
[galgen.git] / galgen.zsh
index e58c88cd9f417034f7a083353cf6bf15a109106c..55e24e84300dc39da2d62a4b82ec8a9bf5289421 100755 (executable)
@@ -1,10 +1,11 @@
 #!/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
@@ -13,14 +14,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
@@ -85,8 +89,13 @@ 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
+        cat .txt >> $dst
+        echo "</pre>" >> $dst
+    }
     [[ $p -eq 1 ]] ||
         echo "<a href=\"$(( $p - 1 )).page.html\">&lt;&lt;&lt;</a>" >> $dst
     [[ $p -eq $pages ]] ||
@@ -98,7 +107,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