From f73a442d1330362d1a64498ba3f60074dfabcb7d Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Mon, 14 Mar 2022 10:16:13 +0300 Subject: [PATCH] More performance optimizations --- zk.zsh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/zk.zsh b/zk.zsh index eb05aff..b6b6407 100755 --- 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//&/&} data=${data///>} - [[ ( $page = "Index" ) || ( $page =~ "/Index" ) ]] \ - && _links=(${(k)pages}) || _links=(${=links[$page]}) - for p ($_links) { + for p (${=links[$page]}) { getrel $page $p data="${data//\[${p}\]/[$p]}" } @@ -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} } -- 2.44.0