]> git.plutz.net Git - serve0/blob - list.sh
list view / index view
[serve0] / list.sh
1 #!/bin/sh
2
3 list_dir(){
4   dir="$(HTML "$1")"
5   printf '[a .list .dir href="%s" %s]' \
6     "$dir" "$dir"
7 }
8
9 list_file(){
10   file="$(HTML "$1")"
11   printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \
12     "$file" "$file" "$file"
13 }
14
15 list_dirs(){
16   (cd "$_DATA/$ITEM";
17    find ./ -type d -mindepth 1 -maxdepth 1 \
18      -exec stat -c '%Y  %n' '{}' +
19    ) \
20   | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
21   | cut -d/ -f2-
22 }
23
24 list_files(){
25   (cd "$_DATA/$ITEM";
26    find ./ -type f -mindepth 1 -maxdepth 1 \
27      -exec stat -c '%Y  %n' "${f#./}" '{}' +
28    ) \
29   | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
30   | cut -d/ -f2-
31 }
32
33 list_tree(){
34   (cd "$_DATA/$ITEM";
35    find ./ -type f \
36      -exec stat -c '%Y  %n' '{}' +
37    ) \
38   | { [ "$(GET o)" = Date ] && sort -rn || sort -k 2; } \
39   | cut -d/ -f2-
40 }
41
42 printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
43
44 "$_EXEC/cgilite/html-sh.sed" <<-EOF
45 [!DOCTYPE HTML]
46 [html [head [title Listing]
47   [link rel=stylesheet href="/style.css" ]
48 ] [body
49   $(w_search)
50   [input type=checkbox #t_prefs .toggle ][label for=t_prefs &#x2699;]
51   $(w_prefs)
52   $(if [ $(COOKIE mode) = index ]; then
53     list_tree  |while read -r file; do list_file "$file"; done
54   else
55     list_dirs  |while read -r  dir; do list_dir   "$dir"; done
56     printf '[br]'
57     list_files |while read -r file; do list_file "$file"; done
58   fi)
59 ] ]
60 EOF
61