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