+list_filemeta(){
+ local meta base cbase fm cachename
+ base="$1"
+ meta="$_DATA/$ITEM/$base/.index/meta"
+ meta_dir "$_DATA/$ITEM/$base"
+
+ cachename="$(printf '%s\n' "$mode" "$FILTER" "$SEARCH" "$ORDER" |sha1sum)"
+ cachename="$_DATA/$ITEM/.index/${cachename% -}.cache"
+
+ if [ "$cachename" -nt "$meta" ] 2>&-; then
+ cat "$cachename"
+ else
+ cbase="$(STRING "$base")"
+ grep -axE '[0-9]+ [0-9]+ [0-9]+ tags=[^ ]* comment=[^ ]* .+' "$meta" \
+ | while read -r fm; do
+ printf '%s %s/%s\n' "${fm% *}" "$cbase" "${fm##* }"
+ done \
+ | list_filter \
+ | list_order \
+ | { [ -d "${meta%meta}" ] && tee "$cachename" || cat; }
+ fi
+}
+
+list_items() {
+ local mode meta
+ mode="$(COOKIE mode |grep -m1 -axE 'index|browse' || printf index )"
+
+ if [ "$mode" = browse ]; then
+ [ "$ITEM" ] && printf 'dir\t..\n'
+ (cd "$_DATA/$ITEM";
+ find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \
+ ) | cut -d/ -f2- | sort |sed 's;^;dir\t;;'
+ list_filemeta .
+ elif [ "$mode" = index ]; then
+ (cd "$_DATA/$ITEM";
+ find ./ -path '*/.index/meta'
+ ) | while read -r meta; do
+ list_filemeta "${meta%/.index/meta}"
+ done
+ fi
+}
+
+list_paginate() {
+ local page i c n end qry
+ page="$(GET p |grep -axE '[0-9]+' || printf 1)"; c=1
+ end=$((page + LISTSIZE))
+ qry="${w_refuri#*\?}"; qry="${qry#p=*&}"
+
+ printf '[div .itemlist '
+ while read -r i; do
+ c=$((c + 1))
+ [ $c -gt $page -a $c -le $end ] && list_item "$i"
+ done
+ printf ']'
+
+ [ $(( c % LISTSIZE )) -gt 0 ] \
+ && end=$((c / LISTSIZE + 1)) \
+ || end=$((c / LISTSIZE))
+
+ printf '[div .pagination'
+ for n in $( seq 1 $end ); do
+ c=$(( (n - 1) * LISTSIZE + 1 ))
+ [ $c = $page ] \
+ && printf '[a .page .current href="%s" %s]' "?p=${c}&${qry}" "$n" \
+ || printf '[a .page href="%s" %s]' "?p=${c}&${qry}" "$n"
+ done
+ printf ']'