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]} ]] || continue
37 links[$p]="$w ${links[$p]}"
41 # Deduplicate all references
42 for p w (${(kv)links}) {
45 for w ($ws) backs[$w]="$p ${backs[$w]}"
47 for p w (${(kv)backs}) {
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=`< $page` || data=$2
76 data="${data//&/&}"
77 data="${data//</<}"
78 data="${data//>/>}"
80 [[ $p = index ]] && continue
82 data="${data//${p}/<a href=\"${REPLY}.html\">$p</a>}"
84 print "<\!DOCTYPE html>
85 <html><head><title>$page (${pages[$page]})</title></head><body><pre>
88 for p (${(oi)=${backs[$page]}}) {
90 print "<li><a href=\"${REPLY}.html\">$p</a> <sup>${pages[$p]}</sup></li>"
92 print "</ul></body></html>"
96 (links) for w (${(oi)=${links[$2]}}) print $w ;;
97 (backs) for w (${(oi)=${backs[$2]}}) print $w ;;
100 for p (${(k)pages}) {
103 genhtml $p > $2/$p.html
106 for p (${(Oi)${(k)pages}}) all=("$p (${pages[$p]})" $all)
107 zmodload -F zsh/datetime b:strftime
108 pages[ALL]=$(strftime "%F %T")
109 genhtml ALL ${(j:\n:)all} > $2/ALL.html