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 =~ "\[(.*)\]" ]] || continue
32 [[ ${pages[$w]} ]] || continue
33 links[$p]="$w ${links[$p]}"
37 # Deduplicate all references
38 for p w (${(kv)links}) {
41 for w ($ws) backs[$w]="$p ${backs[$w]}"
43 for p w (${(kv)backs}) {
50 # nearly the copy-paste of Functions/Misc/relative
55 abs=(${(s:/:)dst:h} $dst:t)
57 while [[ i -le $#abs && $abs[i] == $cur[i] ]] ; do
59 REPLY=${(j:/:)abs[i,-1]}
63 src=${(j:/:)cur[i,-1]/*/..}
64 dst=${(j:/:)abs[i,-1]}
65 REPLY=$src${dst:+/$dst}
71 [[ $# -eq 1 ]] && data=`< $page` || data=$2
72 data="${data//&/&}"
73 data="${data//</<}"
74 data="${data//>/>}"
76 [[ $p = index ]] && continue
78 data="${data//${p}/<a href=\"${REPLY}.html\">$p</a>}"
80 print "<\!DOCTYPE html>
81 <html><head><title>$page</title></head><body><pre>
84 for p (${(oi)=${backs[$page]}}) {
86 print "<li><a href=\"${REPLY}.html\">$p</a></li>"
88 print "</ul></body></html>"
92 (links) for w (${(oi)=${links[$2]}}) print $w ;;
93 (backs) for w (${(oi)=${backs[$2]}}) print $w ;;
99 genhtml $p > $2/$p.html
102 for p (${(Oi)${(k)pages}}) all="$p\n$all"
103 genhtml ALL $all > $2/ALL.html