# Copyright (C) 2022 Sergey Matveev <stargrave@stargrave.org>
set -e
+ZK_VERSION=ZKZSH1
usage() {
cat >&2 <<EOF
zmodload -F zsh/files b:zf_mkdir
typeset -A links
typeset -A backs
+typeset -A cached
typeset -aU ws
for p (${(k)pages}) {
+ [[ $ZK_CACHE ]] && {
+ zstat -A inode +inode $p
+ zstat -A ctime +ctime $p
+ cache=(${(f)mapfile[$ZK_CACHE/$p]})
+ if [[ ( ${cache[1]} = $ZK_VERSION ) &&
+ ( ${cache[2]} = ${inode[1]} ) &&
+ ( ${cache[3]} = ${ctime[1]} ) ]]; then
+ ws=(${cache[4,-1]})
+ [[ $ws ]] && links[$p]=${(j: :)ws}
+ cached[$p]=1
+ continue
+ fi
+ }
ws=()
for w (${=mapfile[$p]}) {
[[ $w =~ "\[([^] ]+)\]" ]] || continue
}
ws=($ws $w)
}
+ [[ $ZK_CACHE ]] && {
+ zf_mkdir -p $ZK_CACHE/$p:h
+ ws=($ZK_VERSION ${inode[1]} ${ctime[1]} $ws)
+ print -l $ws > $ZK_CACHE/$p
+ ws=(${ws[3,-1]})
+ }
[[ $ws ]] && links[$p]=${(j: :)ws}
}
-unset ws
+unset cache ws
for p ws (${(kv)links}) {
for w (${=ws}) backs[$w]="$p ${backs[$w]}"
}
local page=$1
local data p
[[ $# -eq 1 ]] && data=${mapfile[$page]} || data=$2
- data=${data//&/&}
- data=${data//</<}
- data=${data//>/>}
local _links=(${(oi)=links[$page]})
- for p ($_links) {
- getrel $page $p
- data="${data//\[${p}\]/<a href=\"${REPLY}.html\">[$p]</a>}"
- }
- print -r "<\!DOCTYPE html>
+ if [[ ( ${cached[$page]} ) && ( -s $ZK_CACHE/${page}.html ) ]]; then
+ cat $ZK_CACHE/${page}.html
+ else
+ data=${data//&/&}
+ data=${data//</<}
+ data=${data//>/>}
+ for p ($_links) {
+ getrel $page $p
+ data="${data//\[${p}\]/<a href=\"${REPLY}.html\">[$p]</a>}"
+ }
+ data="<!DOCTYPE html>
<html><head><title>$page (${pages[$page]})</title></head><body><pre>
-$data
-</pre>"
+$data</pre>"
+ if [[ $ZK_CACHE ]]; then
+ print -r "$data" > $ZK_CACHE/${page}.html
+ cat $ZK_CACHE/${page}.html
+ else
+ print -r "$data"
+ fi
+ fi
if [[ $_links ]]; then
print "<hr/>Links:<ul>"
for p ($_links) {
for p (${(oi)_links}) \
entries=($entries "[$p] (${pages[$p]}) (${sizes[$p]} bytes)")
if [[ $cats ]]; then
- entries=($entries "\nSubdirectories:\n")
+ entries=($entries " " "Subdirectories:" " ")
for p (${(oi)cats}) {
entries=($entries "[$p/Index]")
_links=($p/Index $_links)