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 for p (**(/)) cats=($p $cats)
31 # Determine the links between them
36 [[ $w =~ "\[(.*)\]" ]] || continue
38 [[ ${pages[$w]} ]] || {
39 [[ $ZK_SHOW_MISSING ]] && print "Missing $w"
42 links[$p]="$w ${links[$p]}"
46 # Deduplicate all references
47 for p w (${(kv)links}) {
50 for w ($ws) backs[$w]="$p ${backs[$w]}"
52 for p w (${(kv)backs}) {
58 # nearly the copy-paste of Functions/Misc/relative
63 abs=(${(s:/:)dst:h} $dst:t)
65 while [[ i -le $#abs && $abs[i] == $cur[i] ]] ; do
67 REPLY=${(j:/:)abs[i,-1]}
71 src=${(j:/:)cur[i,-1]/*/..}
72 dst=${(j:/:)abs[i,-1]}
73 REPLY=$src${dst:+/$dst}
79 [[ $# -eq 1 ]] && data=`< $page` || data=$2
80 data="${data//&/&}"
81 data="${data//</<}"
82 data="${data//>/>}"
84 [[ $p = index ]] && continue
86 data="${data//\[${p}\]/<a href=\"${REPLY}.html\">[$p]</a>}"
88 print "<\!DOCTYPE html>
89 <html><head><title>$page (${pages[$page]})</title></head><body><pre>
92 local bs=(${(oi)=${backs[$page]}})
95 for p (${(oi)=${backs[$page]}}) {
97 print "<li><a href=\"${REPLY}.html\">$p</a> <sup>${pages[$p]}</sup></li>"
101 print "</body></html>"
104 zmodload -F zsh/datetime b:strftime
105 now=$(strftime "%F %T")
111 local curdepth=${#${(s:/:)1}}
112 (( curdepth = curdepth + 1 ))
113 for p (${(oi)${(k)pages[(I)$1*]}}) {
114 [[ $p =~ "/Index$" ]] && continue
115 case ${#${(As:/:)p}} in
116 ($curdepth) entries=($entries "[$p] (${pages[$p]})") ;;
117 ( $(( $curdepth + 1 )) ) cats=(${1}${${p#$1}%%/*} $cats) ;;
122 entries=($entries "------------------------ >8 ------------------------")
123 for p (${(oi)cats}) entries=($entries "[$p/Index]")
125 genHTML ${1}Index ${(F)entries}
129 (links) for w (${(oi)=${links[$2]}}) print $w ;;
130 (backs) for w (${(oi)=${backs[$2]}}) print $w ;;
132 (html-index) genIndex $2 ;;
134 for p (${(k)pages}) {
136 genHTML $p > $2/$p.html
137 touch -r $p $2/$p.html
139 for p ($cats) pages[${p}/Index]=$now
141 for p ($cats) genIndex $p/ > $2/$p/Index.html
142 genIndex "" > $2/Index.html
143 for p ("" $cats) touch -d ${now/ /T} $2/$p/Index.html