]> git.plutz.net Git - shellwiki/blob - macros/gallery
306c517352237b784d3904467bb047a6cf2c7bdc
[shellwiki] / macros / gallery
1 #!/bin/sh
2
3 . "$_EXEC/cgilite/cgilite.sh"
4 . "$_EXEC/acl.sh"
5 . "$_EXEC/tools.sh"
6
7 [ $# = 0 ] && set -- "*"
8
9 printf '<div class="macro gallery">'
10 for glob in "$@"; do
11   page="${glob%/*}"
12   [ "$page" = "$glob" ] && page=./
13   [ ! "$page" ]         && page=/
14
15   acl_read "$(page_abs "${page}")" \
16   && attachment_glob "$glob"
17 done \
18 | grep -xiE '.*\.jpe?g|.*\.png|.*\.gif' \
19 | sort -u \
20 | while read attachment; do
21   case $attachment in
22     */*)
23       printf '<a href="%s"><img src="%s"></a>' \
24              "${attachment%/*}/[attachment]/${attachment##*/}" "${attachment}"
25       ;;
26     *)
27       printf '<a href="%s"><img src="%s"></a>' \
28              "[attachment]/${attachment}" "${attachment}"
29       ;;
30   esac
31 done
32 printf '</div>'