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
38 local ws=(${(u)=links[$p]})
40 for w ($ws) backs[$w]="$p ${backs[$w]}"
43 local ws=(${(u)=backs[$p]})
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="`cat $page`" || data=$2
72 data="${data//&/&}"
73 data="${data//</<}"
74 data="${data//>/>}"
76 [[ $p = ALL ]] && continue
77 [[ $p = index ]] && continue
79 data="${data//${p}/<a href=\"${tgt}.html\">$p</a>}"
81 print "<\!DOCTYPE html>
82 <html><head><title>$page</title></head><body><pre>
85 for p (${(oi)=${backs[$page]}}) {
86 [[ $p = ALL ]] && continue
88 print "<li><a href=\"${tgt}.html\">$p</a></li>"
90 print "</ul></body></html>"
94 (links) for w (${(oi)=${links[$2]}}) print $w ;;
95 (backs) for w (${(oi)=${backs[$2]}}) print $w ;;
101 genhtml $p > $2/$p.html
104 for p (${(Oi)${(k)pages}}) all="$p\n$all"
105 genhtml ALL $all > $2/ALL.html