11 Print who backlinks to the PAGE
18 [[ $# -eq 2 ]] || usage
21 setopt GLOB_STAR_SHORT
23 for f (**(.)) pages[$f]=1
25 # Determine the links between them
30 [[ $w =~ "^[([{].*" ]] && w=${MATCH[2,-2]}
31 [[ ${pages[$w]} ]] || continue
32 links[$p]="$w ${links[$p]}"
36 # Deduplicate all references
37 for p w (${(kv)links}) {
40 for w ($ws) backs[$w]="$p ${backs[$w]}"
42 for p w (${(kv)backs}) {
49 # nearly the copy-paste of Functions/Misc/relative
54 abs=(${(s:/:)dst:h} $dst:t)
56 while [[ i -le $#abs && $abs[i] == $cur[i] ]] ; do
58 REPLY=${(j:/:)abs[i,-1]}
62 src=${(j:/:)cur[i,-1]/*/..}
63 dst=${(j:/:)abs[i,-1]}
64 REPLY=$src${dst:+/$dst}
70 [[ $# -eq 1 ]] && data=`< $page` || data=$2
71 data="${data//&/&}"
72 data="${data//</<}"
73 data="${data//>/>}"
75 [[ $p = index ]] && continue
77 data="${data//${p}/<a href=\"${REPLY}.html\">$p</a>}"
79 print "<\!DOCTYPE html>
80 <html><head><title>$page</title></head><body><pre>
83 for p (${(oi)=${backs[$page]}}) {
85 print "<li><a href=\"${REPLY}.html\">$p</a></li>"
87 print "</ul></body></html>"
91 (links) for w (${(oi)=${links[$2]}}) print $w ;;
92 (backs) for w (${(oi)=${backs[$2]}}) print $w ;;
98 genhtml $p > $2/$p.html
101 for p (${(Oi)${(k)pages}}) all="$p\n$all"
102 genhtml ALL $all > $2/ALL.html