]> Sergey Matveev's repositories - galgen.git/blobdiff - galgen.zsh
There can be grayscale images
[galgen.git] / galgen.zsh
index 86d97c9b2bbaa3c1f9bd6c5f8585e49ed426804b..479d42106dc3d2c40ce4d2b56d97058326ae929e 100755 (executable)
@@ -1,29 +1,67 @@
 #!/usr/bin/env zsh
 # Copyright (C) 2022-2023 Sergey Matveev <stargrave@stargrave.org>
 
-pagesize=${PAGESIZE:-100}
+VERSION=0.1.0
 
 set -e
-setopt EXTENDED_GLOB
+
+pagesize=${PAGESIZE:-100}
+ordering=${ORDERING:-Om}
+style=$STYLE
+
+exifTagsOmit=(
+    ExifToolVersion
+    Directory
+    FileAccessDate
+    FileAttributes
+    FileInodeChangeDate
+    FilePermissions
+)
 
 djxl2ppm() {
-    djxl $1 $1.ppm
+    djxl $1 $1.ppm || {
+        djxl $1 $1.pgm
+        mv $1.pgm $1.ppm
+    }
     [[ -r ${1}-ec0.ppm ]] || return 0
     mv ${1}-ec0.ppm $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))
+pages=$(( ${#imgs} / $pagesize ))
+[[ $(( $pages * $pagesize )) -lt ${#imgs} ]] && pages=$(( $pages + 1 ))
+
 for (( i=1 ; i <= ${#imgs} ; i++ )) {
     local img=${imgs[$i]}
     echo $i $img
     local dst=$i.img.html
+    local p=$(( ( $i / $pagesize ) + 1 ))
     cat > $dst <<EOF
 <!DOCTYPE html>
-<html><head><title>Image ${i}/${#imgs}: $img</title></head><body>
+<html>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+        <meta name="generator" content="galgen $VERSION">
+        ${style}
+        <title>Image ${i}/${#imgs}: $img</title>
+        <link href="1.page.html" rel="start" title="home">
+        <link href="${p}.page.html" rel="up" title="page">
+EOF
+    [[ $i -eq 1 ]] ||
+        echo "<link href=\"$(( $i - 1 )).img.html\" rel=\"prev\" title=\"previous\">" >> $dst
+    [[ $i -eq ${#imgs} ]] ||
+        echo "<link href=\"$(( $i + 1 )).img.html\" rel=\"next\" title=\"next\">" >> $dst
+    cat >> $dst <<EOF
+    </head>
+<body>
 EOF
     [[ $i -eq 1 ]] ||
         echo "<a href=\"$(( $i - 1 )).img.html\">&lt;&lt;&lt;</a>" >> $dst
+    echo "<a href=\"${p}.page.html\">^^^</a>" >> $dst
     [[ $i -eq ${#imgs} ]] ||
         echo "<a href=\"$(( $i + 1 )).img.html\">&gt;&gt;&gt;</a>" >> $dst
     echo "<hr/><img alt=\"$img\" src=\"$img\"/>" >> $dst
@@ -32,6 +70,7 @@ EOF
         cat ${img}.txt >> $dst
         echo "</pre>" >> $dst
     }
+    [[ -r ${img}.html ]] && cat ${img}.html >> $dst
     echo "<hr/>" >> $dst
     if [[ $img:e = jxl ]] ; then
         echo "<pre>" >> $dst
@@ -65,9 +104,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
@@ -79,18 +118,33 @@ EOF
     touch -r $img $dst
 }
 
-pages=$(( ${#imgs} / $pagesize ))
-[[ $(( $pages * $pagesize )) -lt ${#imgs} ]] && pages=$(( $pages + 1 ))
 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>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+        <meta name="generator" content="galgen $VERSION">
+        ${style}
+        <title>Page ${p}/$pages</title>
+        <link href="1.page.html" rel="start" title="home">
 EOF
-    [[ $p -eq 1 ]] && [[ -r .txt ]] && {
-        echo "<pre>" >> $dst
-        cat .txt >> $dst
-        echo "</pre>" >> $dst
+    [[ $p -eq 1 ]] ||
+        echo "<link href=\"$(( $p - 1 )).page.html\" rel=\"prev\" title=\"previous\">" >> $dst
+    [[ $p -eq $pages ]] ||
+        echo "<link href=\"$(( $p + 1 )).page.html\" rel=\"next\" title=\"next\">" >> $dst
+    cat >> $dst <<EOF
+    </head>
+<body>
+EOF
+    [[ $p -eq 1 ]] && {
+        [[ -r .txt ]] && {
+            echo "<pre>" >> $dst
+            cat .txt >> $dst
+            echo "</pre>" >> $dst
+        }
+        [[ -r .html ]] && cat .html >> $dst
     }
     [[ $p -eq 1 ]] ||
         echo "<a href=\"$(( $p - 1 )).page.html\">&lt;&lt;&lt;</a>" >> $dst