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}) {
57 # nearly the copy-paste of Functions/Misc/relative
62 abs=(${(s:/:)dst:h} $dst:t)
64 while [[ i -le $#abs && $abs[i] == $cur[i] ]] ; do
66 REPLY=${(j:/:)abs[i,-1]}
70 src=${(j:/:)cur[i,-1]/*/..}
71 dst=${(j:/:)abs[i,-1]}
72 REPLY=$src${dst:+/$dst}
78 [[ $# -eq 1 ]] && data=`< $page` || data=$2
79 data="${data//&/&}"
80 data="${data//</<}"
81 data="${data//>/>}"
83 [[ $p = index ]] && continue
85 data="${data//${p}/<a href=\"${REPLY}.html\">$p</a>}"
87 print "<\!DOCTYPE html>
88 <html><head><title>$page (${pages[$page]})</title></head><body><pre>
91 for p (${(oi)=${backs[$page]}}) {
93 print "<li><a href=\"${REPLY}.html\">$p</a> <sup>${pages[$p]}</sup></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 (${pages[$p]})" $all)
110 zmodload -F zsh/datetime b:strftime
111 pages[ALL]=$(strftime "%F %T")
112 genhtml ALL ${(j:\n:)all} > $2/ALL.html