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
40 for w (${=${links[$p]}}) {
42 backs[$w]="$p ${backs[$w]}"
48 for w (${=${backs[$p]}}) ws[$w]=1
54 # nearly the copy-paste of Functions/Misc/relative
59 abs=(${(s:/:)dst:h} $dst:t)
61 while [[ i -le $#abs && $abs[i] == $cur[i] ]] ; do
63 REPLY=${(j:/:)abs[i,-1]}
67 src=${(j:/:)cur[i,-1]/*/..}
68 dst=${(j:/:)abs[i,-1]}
69 REPLY=$src${dst:+/$dst}
75 [[ $# -eq 1 ]] && data="`cat $page`" || data=$2
77 data="${data//&/&}"
78 data="${data//</<}"
79 data="${data//>/>}"
81 [[ $p = ALL ]] && continue
82 [[ $p = index ]] && continue
84 data="${data//${p}/<a href=\"${tgt}.html\">$p</a>}"
86 print "<\!DOCTYPE html>
87 <html><head><title>$page</title></head><body><pre>
90 for p (${(oi)=${backs[$page]}}) {
91 [[ $p = ALL ]] && continue
93 print "<li><a href=\"${tgt}.html\">$p</a></li>"
95 print "</ul></body></html>"
99 (links) for w (${(oi)=${links[$2]}}) print $w ;;
100 (backs) for w (${(oi)=${backs[$2]}}) print $w ;;
103 for p (${(k)pages}) {
106 genhtml $p > $2/$p.html
109 for p (${(Oi)${(k)pages}}) all="$p\n$all"
110 genhtml ALL $all > $2/ALL.html