#!/usr/bin/awk -f # # chainindex -- adds prev/next/index/top chain to thumbnail index pages # (complements thumblinklist) # # usage: chainindex galleries.idxs # chainindex removeold=1 linkprefix=../ backlink=../festivals.html galleries.idxs # # http://www.heikopurnhagen.net/software/chainindex # # This program is available under the terms of the GNU General Public # License (GPL). All usual disclaimers apply! # # Heiko Purnhagen (mail@heikopurnhagen.net) # HP 20070910 based on thumblinklist # HP 20070911 tweaked "top" link, added removeold option # HP 20080811 added "touch" to keep timestamp of index page # HP 20080817 facilitate enables multiple runs, disabled "top" link BEGIN { numlink = 0; backlink = "index.html"; linkprefix = ""; removeold = 0; } { if (NR % 4 == 1) name[numlink] = $0; if (NR % 4 == 2) link[numlink] = $0; if (NR % 4 == 3) thumb[numlink] = $0; if (NR % 4 == 0) { if ($0 != "") { print "ERROR, delimiter at line "NR" not empty: "$0 > "/dev/stderr"; numlink = 0; exit; } else { numlink++; } } } END { print "CHAININDEX number of links: "numlink > "/dev/stderr"; if (numlink) { for (i=0; i0) { if ($0=="") { # remove old navigation arrows (5 lines) getline < oldname; getline < oldname; getline < oldname; getline < oldname; } else if (1==index($0,"

")) { # insert navigation arrows before heading printf "

\n" > link[i]; if (i==0) { printf "\n" > link[i]; } else { printf "\n" > link[i]; } printf "\n" > link[i]; if (i==numlink-1) { printf "\n" > link[i]; } else { printf "\n" > link[i]; } printf "
\"prev\"\"prev\"\"index\"\"next\"\"next\"
\n" > link[i]; # copy heading print $0 >> link[i]; } # else if ($0=="

[top]

") { ## remove old link to top (1 line) # } # else if ($0=="


") { ## insert link to top at end # print "

[top]

" >> link[i]; # print $0 >> link[i]; # } else if (0==index($0,">back<")) { # do not copy backlink (now obsolete) print $0 >> link[i]; } } system ("touch -r " oldname " " link[i]); if (removeold) { system ("rm " oldname); } } } } #--