#!/usr/bin/env zsh set -e usage() { cat >&2 < $#cur)) && { REPLY=${(j:/:)abs[i,-1]} return } done src=${(j:/:)cur[i,-1]/*/..} dst=${(j:/:)abs[i,-1]} REPLY=$src${dst:+/$dst} } genHTML() { local page=$1 local data p [[ $# -eq 1 ]] && data=`< $page` || data=$2 data="${data//&/&}" data="${data///>}" for p (${(k)pages}) { [[ $p = index ]] && continue getrel $page $p data="${data//\[${p}\]/[$p]}" } print "<\!DOCTYPE html> $page (${pages[$page]})
$data
" local bs=(${(oi)=${backs[$page]}}) if [[ $bs ]]; then print "
" fi print "" } zmodload -F zsh/datetime b:strftime now=$(strftime "%F %T") genIndex() { local p local entries=() typeset -aU cats=() local curdepth=${#${(s:/:)1}} (( curdepth = curdepth + 1 )) for p (${(oi)${(k)pages[(I)$1*]}}) { [[ $p =~ "/Index$" ]] && continue case ${#${(As:/:)p}} in ($curdepth) entries=($entries "[$p] (${pages[$p]})") ;; ( $(( $curdepth + 1 )) ) cats=(${1}${${p#$1}%%/*} $cats) ;; (*) continue ;; esac } if [[ $cats ]]; then entries=($entries "------------------------ >8 ------------------------") for p (${(oi)cats}) entries=($entries "[$p/Index]") fi genHTML ${1}Index ${(F)entries} } case $1 in (links) for w (${(oi)=${links[$2]}}) print $w ;; (backs) for w (${(oi)=${backs[$2]}}) print $w ;; (html) genHTML $2 ;; (html-index) genIndex $2 ;; (htmls) for p (${(k)pages}) { mkdir -p $2/$p:h genHTML $p > $2/$p.html touch -r $p $2/$p.html } for p ($cats) pages[${p}/Index]=$now pages[Index]=$now for p ($cats) genIndex $p/ > $2/$p/Index.html genIndex "" > $2/Index.html for p ("" $cats) touch -d ${now/ /T} $2/$p/Index.html ;; (*) usage ;; esac