X-Git-Url: http://git.plutz.net/?a=blobdiff_plain;f=list.sh;h=d6228347bec5006fea4cad050b6c868abb0da8d0;hb=0db89f9e8c8556c3fa08887100e548c2fb09ad43;hp=03b9845e934c9f966c58f69b78af57f51670b6be;hpb=b8e2146aaabd7acdff878cd3061de7e24a0a91b2;p=serve0 diff --git a/list.sh b/list.sh index 03b9845..d622834 100644 --- a/list.sh +++ b/list.sh @@ -6,7 +6,7 @@ list_item() { local name path length width height tags comment n name="$(HTML "$1")" - path="$(HTML "$ITEM/$1")" + path="$(URL "${ITEM}/${1}")" if [ -d "$_DATA/$ITEM/$1" ]; then printf '[a .list .dir href="%s?%s" %s]' \ @@ -28,62 +28,55 @@ list_item() { fi } -list_fs_browse(){ - meta_dir "$_DATA/$ITEM" - (cd "$_DATA/$ITEM"; - find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \ - -exec stat -c '%Y %n' '{}' + - find ./ -type f -mindepth 1 -maxdepth 1 \ - -exec stat -c '%Y %n' '{}' + - ) -} -list_fs_index(){ - local d - find "$_DATA/$ITEM" -type d -name .index \ - | while d="$(line)"; do - meta_dir "${d%/.index}" - done - (cd "$_DATA/$ITEM"; - find ./ \! -path '*/.index/*' -type f \ - -exec stat -c '%Y %n' '{}' + - ) -} - -list_browse(){ - local meta f fn file - meta="$_DATA/$ITEM/.index/meta" - meta_dir "$_DATA/$ITEM" +list_directories(){ (cd "$_DATA/$ITEM"; find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \ ) | cut -d/ -f2- | sort - sort -n "$meta" | cut -f6- \ +} + +[ "$FILTER" ] && list_fex="$( + fex='p' + STRING "$FILTER^" \ + | sed -r 's;\^;\n;g; s;[]\/\(\)\\\^\$\?\.\+\*\;\[\{\}];\\&;g' \ + | while read -r f; do + [ ! "${f#~}" ] && continue + [ "${f#~}" = "$f" ] \ + && fex="/(\ttags=([^\t]*,)?)(${f})((,[^\t]*)?\t)/{${fex}}" \ + || fex="/(\ttags=([^\t]*,)?)(${f#~})((,[^\t]*)?\t)/d; ${fex}" + printf '%s\n' "${fex}" + done \ + | tail -n1 +)" + +list_filemeta(){ + local meta base f fn file + base="$1" + meta="$1/.index/meta" + meta_dir "$_DATA/$ITEM/$base" + + if [ "$FILTER" ]; then + sed -nr "$list_fex" "$_DATA/$ITEM/$meta" + elif [ "${SEARCH#!}" != "${SEARCH}" ]; then + grep -viE "$(STRING "${SEARCH#!}")" "$_DATA/$ITEM/$meta" + else + grep -iE "$(STRING "${SEARCH}")" "$_DATA/$ITEM/$meta" + fi |cut -f1,6- \ | while f="$(line)"; do fn="$(UNSTRING "${f#* }")"; fn="${fn%${CR}}"; - file="$(printf '%s\n' "$_DATA/$ITEM/${fn}".*)" + file="$(printf '%s\n' "$_DATA/$ITEM/$base/${fn}".*)" file="${file##*/}" - [ -e "$_DATA/$ITEM/${file}" ] \ - && printf '%s\n' "${file}" + [ -e "$_DATA/$ITEM/$base/${file}" ] \ + && printf '%s %s\n' "${f%% *}" "${base}/${file}" done } list_index(){ - local meta base fn file + local meta (cd "$_DATA/$ITEM"; find ./ -path '*/.index/meta' ) | while meta="$(line)"; do - base="${meta%/.index/meta}" - meta_dir "$_DATA/$ITEM/$base" - cut -f1,6- <"$_DATA/$ITEM/$meta" \ - | while f="$(line)"; do - fn="$(UNSTRING "${f#* }")"; fn="${fn%${CR}}"; - file="$(printf '%s\n' "$_DATA/$ITEM/$base/${fn}".*)" - file="${file##*/}" - [ -e "$_DATA/$ITEM/$base/${file}" ] \ - && printf '%s %s\n' "${f%% *}" "${base}/${file}" - done - done \ - | sort -n \ - | cut -d/ -f2- + list_filemeta "${meta%/.index/meta}" + done } list_items() { @@ -93,17 +86,27 @@ list_items() { [ "$mode" = browse -a "$ITEM" ] && printf '..\n' if [ "$mode" = browse -a "$ORDER" = Date ]; then - list_fs_browse | sort -rn | cut -d/ -f2- + list_directories + list_filemeta . |cut -f2- \ + | xargs -rd'\n' stat -c '%Y %n' \ + | sort -rn |cut -d/ -f2- elif [ "$mode" = browse -a "$ORDER" = Name ]; then - list_fs_browse | sort -k 2 | cut -d/ -f2- + list_directories + list_filemeta . \ + | sort -k 2 |cut -d/ -f2- elif [ "$mode" = index -a "$ORDER" = Date ]; then - list_fs_index | sort -rn | cut -d/ -f2- + list_index |cut -f2- \ + | xargs -rd'\n' stat -c '%Y %n' \ + | sort -rn | cut -d/ -f2- elif [ "$mode" = index -a "$ORDER" = Name ]; then - list_fs_index | sort -k 2 | cut -d/ -f2- + list_index | sort -k 2 | cut -d/ -f2- elif [ "$mode" = browse -a "$ORDER" = Length ]; then - list_browse + list_directories + list_filemeta . \ + | sort -n |cut -d/ -f2- elif [ "$mode" = index -a "$ORDER" = Length ]; then - list_index + list_index \ + | sort -n |cut -d/ -f2- fi } @@ -135,6 +138,7 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' "$_EXEC/cgilite/html-sh.sed" <<-EOF [!DOCTYPE HTML] [html [head [title Listing] + [meta name="viewport" content="width=device-width"] [link rel=stylesheet href="/style.css" ] ] [body [div #navigation @@ -144,6 +148,7 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n' [a #t_prefs href="#prefs" ⚙] ] $(w_prefs) + $(w_advsearch) [form method=POST action="?a=multitag" $(list_items \