]> git.plutz.net Git - serve0/blobdiff - list.sh
list view / index view
[serve0] / list.sh
diff --git a/list.sh b/list.sh
index b8c3a4e3aa7ed4df91846332612403d284c991a7..cb0e4c159bc9a556638301087c046c1e7a232617 100644 (file)
--- a/list.sh
+++ b/list.sh
@@ -1,5 +1,44 @@
 #!/bin/sh
 
+list_dir(){
+  dir="$(HTML "$1")"
+  printf '[a .list .dir href="%s" %s]' \
+    "$dir" "$dir"
+}
+
+list_file(){
+  file="$(HTML "$1")"
+  printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \
+    "$file" "$file" "$file"
+}
+
+list_dirs(){
+  (cd "$_DATA/$ITEM";
+   find ./ -type d -mindepth 1 -maxdepth 1 \
+     -exec stat -c '%Y %n' '{}' +
+   ) \
+  | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
+  | cut -d/ -f2-
+}
+
+list_files(){
+  (cd "$_DATA/$ITEM";
+   find ./ -type f -mindepth 1 -maxdepth 1 \
+     -exec stat -c '%Y %n' "${f#./}" '{}' +
+   ) \
+  | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
+  | cut -d/ -f2-
+}
+
+list_tree(){
+  (cd "$_DATA/$ITEM";
+   find ./ -type f \
+     -exec stat -c '%Y %n' '{}' +
+   ) \
+  | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
+  | cut -d/ -f2-
+}
+
 printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
 
 "$_EXEC/cgilite/html-sh.sed" <<-EOF
@@ -10,6 +49,13 @@ printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
   $(w_search)
   [input type=checkbox #t_prefs .toggle ][label for=t_prefs &#x2699;]
   $(w_prefs)
+  $(if [ $(COOKIE mode) = index ]; then
+    list_tree  |while read -r file; do list_file "$file"; done
+  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)
 ] ]
 EOF