11 Print who backlinks to the PAGE
18 [[ $# -eq 2 ]] || usage
21 setopt GLOB_STAR_SHORT
22 zmodload -F zsh/stat b:zstat
25 zstat -A reply -F "%F %T" +mtime $p
29 # Determine the links between them
34 [[ $w =~ "\[(.*)\]" ]] || continue
36 [[ ${pages[$w]} ]] || {
37 [[ $ZK_SHOW_MISSING ]] && print "Missing $w"
40 links[$p]="$w ${links[$p]}"
44 # Deduplicate all references
45 for p w (${(kv)links}) {
48 for w ($ws) backs[$w]="$p ${backs[$w]}"
50 for p w (${(kv)backs}) {
56 # nearly the copy-paste of Functions/Misc/relative
61 abs=(${(s:/:)dst:h} $dst:t)
63 while [[ i -le $#abs && $abs[i] == $cur[i] ]] ; do
65 REPLY=${(j:/:)abs[i,-1]}
69 src=${(j:/:)cur[i,-1]/*/..}
70 dst=${(j:/:)abs[i,-1]}
71 REPLY=$src${dst:+/$dst}
77 [[ $# -eq 1 ]] && data=`< $page` || data=$2
78 data="${data//&/&}"
79 data="${data//</<}"
80 data="${data//>/>}"
82 [[ $p = index ]] && continue
84 data="${data//${p}/<a href=\"${REPLY}.html\">$p</a>}"
86 print "<\!DOCTYPE html>
87 <html><head><title>$page (${pages[$page]})</title></head><body><pre>
90 for p (${(oi)=${backs[$page]}}) {
92 print "<li><a href=\"${REPLY}.html\">$p</a> <sup>${pages[$p]}</sup></li>"
94 print "</ul></body></html>"
98 (links) for w (${(oi)=${links[$2]}}) print $w ;;
99 (backs) for w (${(oi)=${backs[$2]}}) print $w ;;
102 for p (${(k)pages}) {
105 genhtml $p > $2/$p.html
108 for p (${(Oi)${(k)pages}}) all=("$p (${pages[$p]})" $all)
109 zmodload -F zsh/datetime b:strftime
110 pages[ALL]=$(strftime "%F %T")
111 genhtml ALL ${(j:\n:)all} > $2/ALL.html