From c59fd5a4946c4d13fc1692e4561878a9bb2b3e17 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Thu, 5 Jul 2018 18:31:14 +0200 Subject: [PATCH] pagination function --- list.sh | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/list.sh b/list.sh index 2f8e139..49b9273 100644 --- a/list.sh +++ b/list.sh @@ -1,17 +1,16 @@ #!/bin/sh -list_dir(){ - name="$(HTML "$1")" - path="$(HTML "${ITEM}/$1")" - printf '[a .list .dir href="%s" %s]' \ - "$path" "$name" -} - -list_file(){ +list_item(){ name="$(HTML "$1")" path="$(HTML "$ITEM/$1")" - printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \ - "$path" "$path" "$name" + + if [ -d "$_DATA/$ITEM/$1" ]; then + printf '[a .list .dir href="%s" %s]' \ + "$path" "$name" + else + printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \ + "$path" "$path" "$name" + fi } list_dirs(){ @@ -42,6 +41,23 @@ list_tree(){ | cut -d/ -f2- } +list_paginate(){ + page="$(GET p |grep -xE '[0-9]+' || printf 1)" + while i="$(line)"; do + c=$((${c-0} + 1)) + if [ $c -lt $page ]; then + true + elif [ $c -lt $((LISTSIZE + page)) ]; then + list_item "$i" + fi + done + + for n in $(seq 1 $((c / LISTSIZE + 1)) ); do + printf '[a .page href="%s" %s]' \ + "?p=$(( (n - 1) * LISTSIZE + 1))" "$n" |tee /dev/stderr + done +} + printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' "$_EXEC/cgilite/html-sh.sed" <<-EOF @@ -53,12 +69,13 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' [input type=checkbox #t_prefs .toggle ][label for=t_prefs ⚙] $(w_prefs) $(if [ "$(COOKIE mode)" = index ]; then - list_tree |while read -r file; do list_file "$file"; done + list_tree else - list_dirs |while read -r dir; do list_dir "$dir"; done - printf '[br]' - list_files |while read -r file; do list_file "$file"; done - fi) + list_dirs + list_files + fi \ + | list_paginate + ) ] ] EOF -- 2.39.2