From: Sergey Matveev Date: Fri, 18 Mar 2022 16:13:00 +0000 (+0300) Subject: Ability to link to directory's index X-Git-Url: http://www.git.stargrave.org/?p=zk.zsh.git;a=commitdiff_plain;h=d957ea0ea4e00198d75ab5b46768f98d25bdcd8c Ability to link to directory's index --- diff --git a/README b/README index 206b6dd..1dfb2c7 100644 --- a/README +++ b/README @@ -13,6 +13,7 @@ zk.zsh -- zettelkästen/wiki/static website helper/generator highlight them with: syntax region zkLink start="\[\S" end="\S]" highlight link zkLink String +* Link to the directory's index can be made with [Dir/] * Use Vim's filename completion (:help compl-filename) to complete directories and filenames in them * fzf (https://github.com/junegunn/fzf) related tools can be diff --git a/zk.zsh b/zk.zsh index b6ac72d..93ad39d 100755 --- a/zk.zsh +++ b/zk.zsh @@ -35,8 +35,8 @@ for p (**(.)) { pages[$p]=${mtime[1]} sizes[$p]=${size[1]} } -typeset -a cats -for p (**(/)) cats=($p $cats) +typeset -A cats +for p (**(/)) cats[$p]=1 zmodload zsh/mapfile zmodload -F zsh/files b:zf_mkdir @@ -62,6 +62,10 @@ for p (${(k)pages}) { for w (${=mapfile[$p]}) { [[ $w =~ "\[([^] ]+)\]" ]] || continue w=${match[1]} + [[ ( $w =~ "/$" ) && ( ${cats[$w[1,-2]]} ) ]] && { + ws=($ws $w) + continue + } [[ ${pages[$w]} ]] || { [[ $ZK_SHOW_MISSING ]] && print "missing $w" continue @@ -114,6 +118,7 @@ genHTML() { data=${data//>/>} for p ($_links) { getrel $page $p + [[ -d $p ]] && REPLY=$REPLY/index data="${data//\[${p}\]/[$p]}" } data=" @@ -153,13 +158,13 @@ genIndex() { local p local entries=() local _links=() - typeset -aU cats=() + typeset -aU _cats=() local curdepth=${#${(s:/:)1}} (( curdepth = curdepth + 1 )) for p (${(k)pages[(I)$1*]}) { case ${#${(As:/:)p}} in ($curdepth) _links=($p $_links) ;; - ( $(( $curdepth + 1 )) ) cats=(${1}${${p#$1}%%/*} $cats) ;; + ( $(( $curdepth + 1 )) ) _cats=(${1}${${p#$1}%%/*} $_cats) ;; (*) continue ;; esac } @@ -171,14 +176,23 @@ genIndex() { print "
  • $p ${pages[$p]} (${sizes[$p]} bytes)
  • " } print "" - if [[ $cats ]]; then + if [[ $_cats ]]; then print "
    Subdirectories:" fi + local bs=(${(oi)=${backs[$1]}}) + if [[ $bs ]]; then + print "
    Backlinks:" + fi print "" } @@ -193,9 +207,9 @@ case $1 in genHTML $p > $2/$p.html touch -r $p $2/$p.html } - for p ($cats) genIndex $p/ > $2/$p/index.html + for p (${(k)cats}) genIndex $p/ > $2/$p/index.html genIndex "" > $2/index.html - for p ("" $cats) touch -d ${now/ /T} $2/$p/index.html + for p ("" ${(k)cats}) touch -d ${now/ /T} $2/$p/index.html ;; (*) usage ;; esac