]> Sergey Matveev's repositories - zk.zsh.git/commitdiff
More performance optimizations
authorSergey Matveev <stargrave@stargrave.org>
Mon, 14 Mar 2022 07:16:13 +0000 (10:16 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 14 Mar 2022 07:16:13 +0000 (10:16 +0300)
zk.zsh

diff --git a/zk.zsh b/zk.zsh
index eb05aff979a2a5a7796cb6a2698a62c787645e35..b6b640700c4a2ba95c9d86c5b28eefca731a72c3 100755 (executable)
--- a/zk.zsh
+++ b/zk.zsh
@@ -74,14 +74,11 @@ getrel() {
 genHTML() {
     local page=$1
     local data p
-    typeset -a _links
     [[ $# -eq 1 ]] && data=`< $page` || data=$2
     data=${data//&/&amp;}
     data=${data//</&lt;}
     data=${data//>/&gt;}
-    [[ ( $page = "Index" ) || ( $page =~ "/Index" ) ]] \
-        && _links=(${(k)pages}) || _links=(${=links[$page]})
-    for p ($_links) {
+    for p (${=links[$page]}) {
         getrel $page $p
         data="${data//\[${p}\]/<a href=\"${REPLY}.html\">[$p]</a>}"
     }
@@ -107,21 +104,27 @@ now=$(strftime "%F %T")
 genIndex() {
     local p
     local entries=()
+    local _links=()
     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) _links=($p $_links) ;;
         ( $(( $curdepth + 1 )) ) cats=(${1}${${p#$1}%%/*} $cats) ;;
         (*) continue ;;
         esac
     }
+    for p (${(oi)_links}) entries=($entries "[$p] (${pages[$p]})")
     if [[ $cats ]]; then
-        entries=($entries "------------------------ >8 ------------------------")
-        for p (${(oi)cats}) entries=($entries "[$p/Index]")
+        entries=($entries "\nBacklinks:\n")
+        for p (${(oi)cats}) {
+            entries=($entries "[$p/Index]")
+            _links=($p/Index $_links)
+        }
     fi
+    links[${1}Index]=${(j: :)_links}
     genHTML ${1}Index ${(F)entries}
 }