]> Sergey Matveev's repositories - zk.zsh.git/commitdiff
Lighter, simpler and cleaner indices HTML generation
authorSergey Matveev <stargrave@stargrave.org>
Thu, 17 Mar 2022 17:35:07 +0000 (20:35 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Thu, 17 Mar 2022 17:35:07 +0000 (20:35 +0300)
zk.zsh

diff --git a/zk.zsh b/zk.zsh
index d583ae3d5d3dc5a990578bad5599916e9605a347..b6ac72d05e46e06d663e437ca9a5a41ddf2459e5 100755 (executable)
--- 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 "<!DOCTYPE html>
+<html><head><title>$page ($now)</title></head><body><ul>"
+    for p (${(oi)_links}) {
+        getrel $page $p
+        print "<li><a href=\"${REPLY}.html\">$p</a> <sup>${pages[$p]}</sup> (${sizes[$p]} bytes)</li>"
+    }
+    print "</ul>"
     if [[ $cats ]]; then
-        entries=($entries $separator "Subdirectories:" $separator)
+        print "<hr/>Subdirectories:<ul>"
         for p (${(oi)cats}) {
-            entries=($entries "[$p/index]")
-            _links=($p/index $_links)
+            getrel $page $p/index
+            print "<li><a href=\"${REPLY}.html\">$p</a></li>"
         }
+        print "</ul>"
     fi
-    links[${1}index]=${(j: :)_links}
-    genHTML ${1}index ${(F)entries}
+    print "</body></html>"
 }
 
 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