simplified arg shuffling in index

This commit is contained in:
Jaromil 2014-09-11 19:42:04 +02:00
parent 9d1084aa6f
commit 03e7b6845b
1 changed files with 18 additions and 14 deletions

32
index
View File

@ -34,6 +34,12 @@
# format: filename;size;date
typeset -alU files
# globals set by recursive_index
typeset archive=""
typeset urlsuffix=""
typeset indextype=""
typeset dataurl=""
filetype_icon() {
@ -90,7 +96,7 @@ recursive_index() {
dirs=`find "$archive" -type d`
basedir="/`basename "$archive"`/"
diralias="$2"
urlsuffix="$2"
indextype="$3"
@ -98,7 +104,7 @@ recursive_index() {
func "index archive $archive"
func "index basedir: $basedir"
func "index aliasdir: $diralias"
func "index aliasdir: $urlsuffix"
# copy default icons
mkdir -p $destination/icons$THUMB_SIZE
cp $SYS/icons/$THUMB_SIZE/image-x-generic.png $destination/icons$THUMB_SIZE
@ -127,9 +133,9 @@ EOF
test -r "${d}/README" } && {
print "<div class=\"span4\">" >> index${EXTENSION} }
# takes 3 arguments: base dir, alias dir and indexed directory
# takes 1 argument: indexed directory
# we must check if its the parent directory
index_${indextype%_readme*} "${archive}" "${diralias}" "${dir}" >> index${EXTENSION}
index_${indextype%_readme*} "${dir}" >> index${EXTENSION}
# here also strips the _readme modifier
[[ "$indextype" =~ "readme" ]] && {
@ -155,8 +161,8 @@ EOF
index_short() {
func "index_short \"$1\" \"$2\" \"$3\""
dir="${1}${3}"
func "index_short \"$1\""
dir="${archive}${1}"
{ test -d "$dir" } || { error "cannot index: not a directory '$dir'"; return 1 }
files=()
ttmp=`ls -l --time-style=long-iso "$dir" | awk '
@ -173,8 +179,7 @@ index_short() {
act "${#files} files parsed in $dir"
diralias="$2"
dirbase="$3"
dirbase="$1"
# setup paths for test
if [ "$CMD" = "test" ]; then
@ -182,7 +187,7 @@ index_short() {
tpwd=`pwd`
parent="${tpwd%/*}"
else
LINK_PREFIX="${diralias}${dirbase}"
LINK_PREFIX="${urlsuffix}${dirbase}"
parent=".."
fi
func "LINK_PREFIX = $LINK_PREFIX"
@ -273,8 +278,8 @@ EOF
}
index_long_preview() {
func "index_long_preview \"$1\" \"$2\" \"$3\""
dir="${1}${3}"
func "index_long_preview \"$1\""
dir="${1}"
{ test -d "$dir" } || { error "cannot index: not a directory '$dir'"; return 1 }
files=()
ttmp=`ls -l --time-style=long-iso "$dir" | awk '
@ -290,13 +295,12 @@ index_long_preview() {
act "${#files} files parsed in $dir"
diralias="$2"
dirbase="$3"
dirbase="$1"
# setup paths for test
if [ "$CMD" = "test" ]; then
LINK_PREFIX="file://${dir}"
else
LINK_PREFIX="${diralias}${dirbase}"
LINK_PREFIX="${urlsuffix}${dirbase}"
fi
func "LINK_PREFIX = $LINK_PREFIX"