#!/usr/bin/env zsh
# Copyright (C) 2022-2026 Sergey Matveev <stargrave@stargrave.org>
-VERSION=0.7.0
+VERSION=0.8.0
setopt ERR_EXIT
FilePermissions
)
-[[ -z $style ]] || style="<link rel=\"stylesheet\" type=\"text/css\" href=\"$style\">"
+[[ -z $style ]] || style="<link rel=stylesheet type=\"text/css\" href=\"$style\">"
mkdir -p alt .info preview
setopt EXTENDED_GLOB
for img (*.jxl(N)) { [[ -r .info/$img.img ]] || imgs=($imgs $img) }
[[ ${#imgs} == 0 ]] || {
echo Infos... >&2
- parallel "jxlinfo {} > .info/{}.img" ::: $imgs
+ parallel "jxlinfo {} >.info/{}.img" ::: $imgs
}
imgs=()
src=()
[[ ${#imgs} == 0 ]] || {
echo Exif info... >&2
- parallel "exiftool -escapeHTML -htmlFormat -groupHeadings --${=${(j/ --/)exifTagsOmit}} {} > .info/{}.exif" ::: $imgs
+ parallel "exiftool -escapeHTML -htmlFormat -groupHeadings --${=${(j/ --/)exifTagsOmit}} {} >.info/{}.exif" ::: $imgs
}
imgs=((*.jxl)($ordering))
[[ ${#pngs} == 0 ]] || {
echo PNG generation... >&2
- parallel "$djxl2pam | pamtopng > {}.png" ::: $pngs
+ parallel "$djxl2pam | pamtopng >{}.png" ::: $pngs
parallel "pngcrush -warn -rem alla -rem allb -z 2 {}.png alt/{}.png && rm {}.png" ::: $pngs
parallel "advpng --quiet --recompress -4 alt/{}.png && touch -r {} alt/{}.png" ::: $pngs
}
echo $i $img
local dst=$i.img.html
local p=$(( ( $i / $pagesize ) + 1 ))
- cat > $tmp <<EOF
+ cat >$tmp <<EOF
<!DOCTYPE html>
<html>
<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="generator" content="galgen $VERSION">
+ <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">
+ <link rel=start href="1.page.html" title="home">
+ <link rel=up href="${p}.page.html" title="page">
EOF
[[ $i -eq 1 ]] ||
- echo "<link href=\"$(( $i - 1 )).img.html\" rel=\"prev\" title=\"previous\">" >> $tmp
+ echo "<link rel=prev href=\"$(( $i - 1 )).img.html\" title=\"prev\">" >>$tmp
[[ $i -eq ${#imgs} ]] ||
- echo "<link href=\"$(( $i + 1 )).img.html\" rel=\"next\" title=\"next\">" >> $tmp
- cat >> $tmp <<EOF
+ echo "<link rel=next href=\"$(( $i + 1 )).img.html\" title=\"next\">" >>$tmp
+ cat >>$tmp <<EOF
</head>
<body>
EOF
- [[ $i -eq 1 ]] ||
- echo "<a href=\"$(( $i - 1 )).img.html\"><<<</a>" >> $tmp
- echo "<a href=\"${p}.page.html\">^^^</a>" >> $tmp
- [[ $i -eq ${#imgs} ]] ||
- echo "<a href=\"$(( $i + 1 )).img.html\">>>></a>" >> $tmp
- echo "<hr/><img alt=\"$img\" src=\"$img\" />" >> $tmp
+ echo "<img alt=\"$img\" src=\"$img\" />" >>$tmp
[[ ! -r ${img}.txt ]] || {
- echo "<hr/><pre>" >> $tmp
- cat ${img}.txt >> $tmp
- echo "</pre>" >> $tmp
+ echo "<pre>" >>$tmp
+ cat ${img}.txt >>$tmp
+ echo "</pre>" >>$tmp
}
- [[ ! -r ${img}.html ]] || { cat ${img}.html >> $tmp }
- echo "<hr/>" >> $tmp
+ [[ ! -r ${img}.html ]] || { cat ${img}.html >>$tmp }
[[ -r .info/$img.img ]]
- echo "<pre>" >> $tmp
- cat .info/$img.img >> $tmp
- echo "</pre>" >> $tmp
+ echo "<pre>" >>$tmp
+ cat .info/$img.img >>$tmp
+ echo "</pre>" >>$tmp
[[ -n "$NOALT" ]] || {
if [[ $img:e = jxl ]] ; then
- echo "Alternative formats:" >> $tmp
+ echo "Alternative formats:" >>$tmp
[[ -r alt/$img.jpg ]] && {
- echo "<a href=\"alt/$img.jpg\">JPEG</a>" >> $tmp
+ echo "<a href=\"alt/$img.jpg\">JPEG</a>" >>$tmp
} || {
- echo "<a href=\"alt/$img.png\">PNG</a>" >> $tmp
+ echo "<a href=\"alt/$img.png\">PNG</a>" >>$tmp
}
fi
- echo "<hr/>" >> $tmp
}
[[ -r .info/$img.exif ]]
- cat .info/$img.exif >> $tmp
- echo "</body></html>" >> $tmp
+ cat .info/$img.exif >>$tmp
+ echo "</body></html>" >>$tmp
cmp -s $tmp $dst || {
- cat $tmp > $dst
+ cat $tmp >$dst
touch -r $img $dst
}
}
for (( p=1 ; p <= $pages ; p++ )) {
local dst=$p.page.html
- cat > $tmp <<EOF
+ cat >$tmp <<EOF
<!DOCTYPE html>
<html>
<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta name="generator" content="galgen $VERSION">
+ <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">
+ <link rel=start href="1.page.html" title="home">
+ <link rel=end href="${pages}.page.html" title="end">
EOF
[[ $p -eq 1 ]] ||
- echo "<link href=\"$(( $p - 1 )).page.html\" rel=\"prev\" title=\"previous\">" >> $tmp
+ echo "<link rel=prev href=\"$(( $p - 1 )).page.html\" title=\"prev\">" >>$tmp
[[ $p -eq $pages ]] ||
- echo "<link href=\"$(( $p + 1 )).page.html\" rel=\"next\" title=\"next\">" >> $tmp
- cat >> $tmp <<EOF
+ echo "<link rel=next href=\"$(( $p + 1 )).page.html\" title=\"next\">" >>$tmp
+ cat >>$tmp <<EOF
</head>
<body>
EOF
[[ $p -ne 1 ]] || {
[[ ! -r .txt ]] || {
- echo "<pre>" >> $tmp
- cat .txt >> $tmp
- echo "</pre>" >> $tmp
+ echo "<pre>" >>$tmp
+ cat .txt >>$tmp
+ echo "</pre>" >>$tmp
}
- [[ ! -r .html ]] || { cat .html >> $tmp }
+ [[ ! -r .html ]] || { cat .html >>$tmp }
}
- [[ $p -eq 1 ]] ||
- echo "<a href=\"$(( $p - 1 )).page.html\"><<<</a>" >> $tmp
- [[ $p -eq $pages ]] ||
- echo "<a href=\"$(( $p + 1 )).page.html\">>>></a>" >> $tmp
- echo "| <a href=\"1.page.html\">home</a>" >> $tmp
- echo "| <a href=\"${pages}.page.html\">end</a>" >> $tmp
- echo "<hr/>" >> $tmp
for (( i=1 ; i <= $pagesize ; i++ )) {
img=$(( ( $p - 1 ) * $pagesize + $i ))
[[ $img -le ${#imgs} ]] || break
- echo "<a href=\"${img}.img.html\">" >> $tmp
+ echo "<a href=\"${img}.img.html\">" >>$tmp
alt="preview ${img}"
title=""
[[ ! -r ${imgs[$img]}.txt ]] || {
alt=`cat ${imgs[$img]}.txt`
title="title=\"$alt\""
}
- echo "<img alt=\"$alt\" $title src=\"preview/${imgs[$img]}.webp\" /></a>" >> $tmp
+ echo "<img alt=\"$alt\" $title src=\"preview/${imgs[$img]}.webp\" /></a>" >>$tmp
}
- echo "</body></html>" >> $tmp
+ echo "</body></html>" >>$tmp
cmp -s $tmp $dst || {
- cat $tmp > $dst
+ cat $tmp >$dst
echo page $p
}
}