]> git.plutz.net Git - serve0/blob - list.sh
indexing stubs
[serve0] / list.sh
1 #!/bin/sh
2
3 list_item(){
4   name="$(HTML "$1")"
5   path="$(HTML "$ITEM/$1")"
6
7   if [ -d "$_DATA/$ITEM/$1" ]; then
8     printf '[a .list .dir href="%s" %s]' \
9       "$path" "$name"
10   else
11     printf '[div .list .file [a href="%s" [img src="%s?a=thumbnail"] %s]]' \
12       "$path" "$path" "$name"
13   fi
14 }
15
16 list_items(){
17   mode="$(COOKIE mode |grep -m1 -xE 'index|browse' || printf browse )"
18
19   [ "$mode" = browse -a "$ITEM" ] && printf '..\n'
20   if [ "$mode" = browse ]; then
21     [ -d "$_DATA/$ITEM/.index" -a "$_DATA/$ITEM" -nt "$_DATA/$ITEM/.index/meta" ] \
22     && . "$_EXEC/update_meta.sh"
23     (cd "$_DATA/$ITEM";
24      find ./ -type d \! -name .index -mindepth 1 -maxdepth 1 \
25        -exec stat -c '%Y        %n' '{}' +
26      find ./ -type f -mindepth 1 -maxdepth 1 \
27        -exec stat -c '%Y        %n' '{}' +
28     )
29   elif [ "$mode" = index ]; then
30     (cd "$_DATA/$ITEM";
31      find ./ -type f \
32        -exec stat -c '%Y        %n' '{}' +
33     )
34   fi \
35   | case $ORDER in
36     Date) sort -rn;;
37     Name) sort -k 2;;
38   esac \
39   | cut -d/ -f2-
40     
41 }
42
43 list_paginate(){
44   page="$(GET p |grep -xE '[0-9]+' || printf 1)"
45
46   printf '[div .itemlist '
47   while i="$(line)"; do
48     c=$((${c-0} + 1))
49     if [ $c -lt $page ]; then
50       true
51     elif [ $c -lt $((LISTSIZE + page)) ]; then
52       list_item "$i"
53     fi
54   done
55   printf ']'
56
57   printf '[div .pagination'
58   for n in $(seq 1 $((c / LISTSIZE + 1)) ); do
59     printf '[a .page href="%s" %s]' \
60       "?p=$(( (n - 1) * LISTSIZE + 1))" "$n"
61   done
62   printf ']'
63 }
64
65 printf 'Content-Type: text/html;charset=utf-8\r\n\r\n'
66
67 "$_EXEC/cgilite/html-sh.sed" <<-EOF
68 [!DOCTYPE HTML]
69 [html [head [title Listing]
70   [link rel=stylesheet href="/style.css" ]
71 ] [body
72   [div #navigation
73     [a #t_bookmarks href="#bookmarks" &#x2605;]
74     $(w_search)
75     [a #t_avsearch href="#advsearch" Advanced]
76     [a #t_prefs href="#prefs" &#x2699;]
77   ]
78   $(w_prefs)
79
80   $(list_items \
81     | list_paginate
82   )
83   [div #editing
84     $(w_index)
85   ]
86 ] ]
87 EOF
88