From 95c1084debae483c5674606175d7e9903675643e Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Thu, 17 Mar 2022 20:35:07 +0300 Subject: [PATCH] Lighter, simpler and cleaner indices HTML generation --- zk.zsh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/zk.zsh b/zk.zsh index d583ae3..b6ac72d 100755 --- a/zk.zsh +++ b/zk.zsh @@ -156,25 +156,30 @@ genIndex() { typeset -aU cats=() local curdepth=${#${(s:/:)1}} (( curdepth = curdepth + 1 )) - for p (${(oi)${(k)pages[(I)$1*]}}) { - [[ ( $p =~ "/index$" ) || ( $p = "index" ) ]] && continue + for p (${(k)pages[(I)$1*]}) { case ${#${(As:/:)p}} in ($curdepth) _links=($p $_links) ;; ( $(( $curdepth + 1 )) ) cats=(${1}${${p#$1}%%/*} $cats) ;; (*) continue ;; esac } - for p (${(oi)_links}) \ - entries=($entries "[$p] (${pages[$p]}) (${sizes[$p]} bytes)") + local page=${1}index + print " +$page ($now)" if [[ $cats ]]; then - entries=($entries $separator "Subdirectories:" $separator) + print "
Subdirectories:" fi - links[${1}index]=${(j: :)_links} - genHTML ${1}index ${(F)entries} + print "" } case $1 in @@ -188,8 +193,6 @@ case $1 in 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 -- 2.44.0