ref: df7f8a52cc82dbfed24fee9f09aa37ac47708846
parent: 6e2495194d26f3dc492d31469ea2ff48e4971b2c
author: Alex Musolino <musolinoa@gmail.com>
date: Wed Aug 23 23:14:25 EDT 2023
mkalbumindex.rc: try harder to find targets for next/prev links
--- a/mkalbumindex.rc
+++ b/mkalbumindex.rc
@@ -1,8 +1,7 @@
#!/bin/rc
this=`{basename `{pwd}}
-prev=`{echo $this - 1 | bc | sed 's/^.$/0&/'}
-next=`{echo $this + 1 | bc | sed 's/^.$/0&/'}
+year=`{basename `{dirname `{pwd}}}
cat <<EOF
<!DOCTYPE html>
@@ -28,15 +27,48 @@
<p>
EOF
-if(test -d ../^$"prev)
- echo '<a href="../'^$"prev^'/index.html">prev</a>'
-if not
+fn findnext1{
+ for(i in `{seq $2 $3 $4 | sed 's/^.$/0&/'}){
+ if(test -d ../../$1/^$i){
+ echo $1/$i
+ exit
+ }
+ }
+}
+
+fn findnext{
+ @{
+ findnext1 $1 `{echo $2 $3 | bc} $3 $4
+
+ end=1990
+ ms=12
+ me=1
+ if(~ $3 +1){
+ end=`{date '+%Y'}
+ ms=1
+ me=12
+ }
+
+ for(y in `{seq `{echo $1 $3 | bc} $3 $end}){
+ if(test -d ../../^$y)
+ findnext1 $y $ms $3 $me
+ }
+ }
+}
+
+prev=`{findnext $year $this -1 1}
+if(~ $#prev 0)
echo '<span class="disabled">prev</span>'
-echo ' | <a href="../index.html">up</a> | '
-if(test -d ../^$"next)
- echo '<a href="../'^$next^'/index.html">next</a>'
if not
+ echo '<a href="../../'^$"prev^'/index.html">prev</a>'
+
+echo ' | <a href="../index.html">'^$year^'</a> | '
+
+next=`{findnext $year $this +1 12}
+if(~ $#next 0)
echo '<span class="disabled">next</span>'
+if not
+ echo '<a href="../../'^$next^'/index.html">next</a>'
echo '</p>'
ls *.thumb.JPG | awk '{ printf "<a href=\"%d.html\"><img src=\"%s\"/></a>\n", NR, $0 }'