From 377d9a9a9992af6d02c6145c5cc5540fae824fe1 Mon Sep 17 00:00:00 2001 From: Sergey Matveev <stargrave@stargrave.org> Date: Wed, 22 Feb 2023 13:41:40 +0300 Subject: [PATCH] More navigation links --- galgen.zsh | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/galgen.zsh b/galgen.zsh index 8124fd8..0e03a3a 100755 --- a/galgen.zsh +++ b/galgen.zsh @@ -27,16 +27,34 @@ djxl2ppm() { 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>${style}<title>Image ${i}/${#imgs}: $img</title></head><body> +<html> + <head> + ${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\"><<<</a>" >> $dst + echo "<a href=\"${p}.page.html\">^^^</a>" >> $dst [[ $i -eq ${#imgs} ]] || echo "<a href=\"$(( $i + 1 )).img.html\">>>></a>" >> $dst echo "<hr/><img alt=\"$img\" src=\"$img\"/>" >> $dst @@ -92,13 +110,23 @@ 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>${style}<title>Page ${p}/$pages</title></head><body> +<html> + <head> + ${style} + <title>Page ${p}/$pages</title> + <link href="1.page.html" rel="start" title="home"> +EOF + [[ $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 -- 2.51.0