mirror of https://github.com/dyne/webnomad.git
good fixes to indexing and support for FILES_ROOT
This commit is contained in:
parent
03e7b6845b
commit
85f04503b9
12
README.md
12
README.md
|
|
@ -100,16 +100,18 @@ of images and linking to the originals.
|
||||||
|
|
||||||
In order to do so create a file in views with extension `.idx` or
|
In order to do so create a file in views with extension `.idx` or
|
||||||
`.index`, then fill it in with the needed configurations, for instance a
|
`.index`, then fill it in with the needed configurations, for instance a
|
||||||
file my_pictures_folder.index can contain
|
file my_pictures_folder.index can contain one line (# is a comment)
|
||||||
|
|
||||||
THUMB_SIZE=128
|
# path to be indexed url subfolder index type
|
||||||
LINK_PREFIX=archive
|
/home/jaromil/pics pics short
|
||||||
index /home/jaromil/pics
|
|
||||||
|
|
||||||
This will produce a pub/my_pictures_folder.html file which will list
|
This will produce a pics/index.html url which will list
|
||||||
all files inside that directory with previews and further links to
|
all files inside that directory with previews and further links to
|
||||||
subfolders that are indexed the same way.
|
subfolders that are indexed the same way.
|
||||||
|
|
||||||
|
In some cases it can be useful to serve the actual downloads from a
|
||||||
|
different place than `WEB_ROOT`, be it another server for assets or an
|
||||||
|
apache alias. To configure this use `FILES_ROOT` in config.zsh.
|
||||||
|
|
||||||
## DEVELOPERS
|
## DEVELOPERS
|
||||||
|
|
||||||
|
|
|
||||||
120
index
120
index
|
|
@ -23,8 +23,6 @@
|
||||||
# filetype_icon() - takes a filename as arg (can be file only or real path)
|
# filetype_icon() - takes a filename as arg (can be file only or real path)
|
||||||
# - returns a filename for the icon to be used from icons/
|
# - returns a filename for the icon to be used from icons/
|
||||||
#
|
#
|
||||||
# index_dir() - indexes a directory into an html file linking all its contents
|
|
||||||
#
|
|
||||||
# preview_file() - takes a filename as arg
|
# preview_file() - takes a filename as arg
|
||||||
# renders the file in a usable format (thumb if image, html if markdown, etc.)
|
# renders the file in a usable format (thumb if image, html if markdown, etc.)
|
||||||
# returns the filename of the rendered result
|
# returns the filename of the rendered result
|
||||||
|
|
@ -34,13 +32,21 @@
|
||||||
# format: filename;size;date
|
# format: filename;size;date
|
||||||
typeset -alU files
|
typeset -alU files
|
||||||
|
|
||||||
# globals set by recursive_index
|
typeset archive="" # full path to be indexed set by recursive_index()
|
||||||
typeset archive=""
|
|
||||||
typeset urlsuffix=""
|
typeset diralias="" # index directory appended to url set by recursive_index()
|
||||||
typeset indextype=""
|
|
||||||
typeset dataurl=""
|
typeset url="" # address at which the web pages are available
|
||||||
|
|
||||||
|
typeset data="" # address from which the data is downloadable
|
||||||
|
|
||||||
|
typeset parent=".." # the directory above the current one
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# filetype_icon()
|
||||||
|
# - takes a filename as arg (can be file only or real path)
|
||||||
|
# - returns a filename for the icon to be used from icons/
|
||||||
filetype_icon() {
|
filetype_icon() {
|
||||||
|
|
||||||
{ test "$1" = "" } && {
|
{ test "$1" = "" } && {
|
||||||
|
|
@ -67,6 +73,7 @@ filetype_icon() {
|
||||||
dmg) res=dmg.png ;;
|
dmg) res=dmg.png ;;
|
||||||
pdf) res=application-pdf.png ;;
|
pdf) res=application-pdf.png ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# analize name
|
# analize name
|
||||||
case $name:l in
|
case $name:l in
|
||||||
changelog) res=text-x-changelog.png ;;
|
changelog) res=text-x-changelog.png ;;
|
||||||
|
|
@ -87,24 +94,45 @@ filetype_icon() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# should be called from inside the destination directory
|
# external call from the render cli interface
|
||||||
|
# should be called from inside the destination directory (pub or test)
|
||||||
|
# it does cascade call anything else necessary in this file
|
||||||
recursive_index() {
|
recursive_index() {
|
||||||
# render_header "<link rel=\"stylesheet\" href=\"css/blueimp-gallery.min.css\" />"
|
# render_header "<link rel=\"stylesheet\" href=\"css/blueimp-gallery.min.css\" />"
|
||||||
{ test -d "$1" } || { error "cannot index directory not found: $1"; return 1 }
|
{ test -d "$1" } || { error "cannot index directory not found: $1"; return 1 }
|
||||||
|
|
||||||
|
# archive: full path where the files to be indexed are found
|
||||||
|
# diralias: index directory appended to url
|
||||||
|
# indextype: type of index (short | long)
|
||||||
|
|
||||||
archive="$1"
|
archive="$1"
|
||||||
dirs=`find "$archive" -type d`
|
|
||||||
basedir="/`basename "$archive"`/"
|
basedir="/`basename "$archive"`/"
|
||||||
|
|
||||||
urlsuffix="$2"
|
diralias="$2"
|
||||||
|
|
||||||
indextype="$3"
|
indextype="$3"
|
||||||
|
|
||||||
dest="`pwd`"
|
dest="`pwd`"
|
||||||
|
|
||||||
func "index archive $archive"
|
# if its a test use the file:// root for test dir
|
||||||
|
[[ "$CMD" = "test" ]] && {
|
||||||
|
url="file://`PWD=${SYS} pwd`"
|
||||||
|
data="file://${archive}" }
|
||||||
|
|
||||||
|
[[ "$url" = "" ]] && { url="$WEB_ROOT/$diralias" }
|
||||||
|
|
||||||
|
[[ "$FILES_ROOT" = "" ]] || { data="$FILES_ROOT" }
|
||||||
|
|
||||||
|
# if no special root is specified then use web_root
|
||||||
|
[[ "$data" = "" ]] && { data="$WEB_ROOT" }
|
||||||
|
|
||||||
|
func "index archive: $archive"
|
||||||
func "index basedir: $basedir"
|
func "index basedir: $basedir"
|
||||||
func "index aliasdir: $urlsuffix"
|
func "index type: $indextype"
|
||||||
|
func "index url: $url"
|
||||||
|
func "index data: $data"
|
||||||
|
|
||||||
# copy default icons
|
# copy default icons
|
||||||
mkdir -p $destination/icons$THUMB_SIZE
|
mkdir -p $destination/icons$THUMB_SIZE
|
||||||
cp $SYS/icons/$THUMB_SIZE/image-x-generic.png $destination/icons$THUMB_SIZE
|
cp $SYS/icons/$THUMB_SIZE/image-x-generic.png $destination/icons$THUMB_SIZE
|
||||||
|
|
@ -112,10 +140,16 @@ recursive_index() {
|
||||||
cp $SYS/icons/$THUMB_SIZE/folder.png $destination/icons$THUMB_SIZE
|
cp $SYS/icons/$THUMB_SIZE/folder.png $destination/icons$THUMB_SIZE
|
||||||
cp $SYS/icons/$THUMB_SIZE/go-up.png $destination/icons$THUMB_SIZE
|
cp $SYS/icons/$THUMB_SIZE/go-up.png $destination/icons$THUMB_SIZE
|
||||||
|
|
||||||
|
dirs=`find "$archive" -type d`
|
||||||
|
|
||||||
for d in ${(f)dirs}; do
|
for d in ${(f)dirs}; do
|
||||||
dir="${d##*${basedir}}"
|
dir="${d##*${basedir}}"
|
||||||
func "actual file path: $d"
|
func "actual file path: $d"
|
||||||
func "relative path: $dir"
|
func "relative path: $dir"
|
||||||
|
|
||||||
|
# we must check if its the parent directory
|
||||||
|
[[ "$dir" = "$archive" ]] && { dir="" }
|
||||||
|
|
||||||
func "destination: ${dest}/${dir}"
|
func "destination: ${dest}/${dir}"
|
||||||
|
|
||||||
mkdir -p "${dest}/${dir}"
|
mkdir -p "${dest}/${dir}"
|
||||||
|
|
@ -133,8 +167,8 @@ EOF
|
||||||
test -r "${d}/README" } && {
|
test -r "${d}/README" } && {
|
||||||
print "<div class=\"span4\">" >> index${EXTENSION} }
|
print "<div class=\"span4\">" >> index${EXTENSION} }
|
||||||
|
|
||||||
# takes 1 argument: indexed directory
|
# string composited function call (indextype supports _appends)
|
||||||
# we must check if its the parent directory
|
# takes 3 arguments: base dir, alias dir and indexed directory
|
||||||
index_${indextype%_readme*} "${dir}" >> index${EXTENSION}
|
index_${indextype%_readme*} "${dir}" >> index${EXTENSION}
|
||||||
# here also strips the _readme modifier
|
# here also strips the _readme modifier
|
||||||
|
|
||||||
|
|
@ -161,37 +195,27 @@ EOF
|
||||||
|
|
||||||
|
|
||||||
index_short() {
|
index_short() {
|
||||||
func "index_short \"$1\""
|
dir="${1}"
|
||||||
dir="${archive}${1}"
|
func "index_short \"$dir\""
|
||||||
{ test -d "$dir" } || { error "cannot index: not a directory '$dir'"; return 1 }
|
func "index data: $archive/$dir"
|
||||||
|
func "index url: $url / $dir"
|
||||||
|
|
||||||
|
{ test -d "$archive/$dir" } || { error "cannot index: not a directory '$archive/$dir'"; return 1 }
|
||||||
files=()
|
files=()
|
||||||
ttmp=`ls -l --time-style=long-iso "$dir" | awk '
|
ttmp=`ls -l --time-style=long-iso "${archive}/${dir}" | awk '
|
||||||
/^total/ { next }
|
/^total/ { next }
|
||||||
/^$/ { next }
|
/^$/ { next }
|
||||||
/'"index${EXTENSION}"'/ { next }
|
/'"index${EXTENSION}"'/ { next }
|
||||||
{ printf "files+=(\"%s\");", $8 }
|
{ printf "files+=(\"%s\");", $8 }
|
||||||
'`
|
'`
|
||||||
{ test $? = 0 } || {
|
{ test $? = 0 } || {
|
||||||
error "Error parsing directory: $dir"
|
error "Error parsing directory: $archive/$dir"
|
||||||
return 1 }
|
return 1 }
|
||||||
func "$ttmp"
|
# func "$ttmp"
|
||||||
eval "$ttmp"
|
eval "$ttmp"
|
||||||
|
|
||||||
act "${#files} files parsed in $dir"
|
act "${#files} files parsed in $dir"
|
||||||
|
|
||||||
dirbase="$1"
|
|
||||||
|
|
||||||
# setup paths for test
|
|
||||||
if [ "$CMD" = "test" ]; then
|
|
||||||
LINK_PREFIX="file://${dir}"
|
|
||||||
tpwd=`pwd`
|
|
||||||
parent="${tpwd%/*}"
|
|
||||||
else
|
|
||||||
LINK_PREFIX="${urlsuffix}${dirbase}"
|
|
||||||
parent=".."
|
|
||||||
fi
|
|
||||||
func "LINK_PREFIX = $LINK_PREFIX"
|
|
||||||
|
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
<table class="table table-hover table-condensed">
|
<table class="table table-hover table-condensed">
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
|
|
@ -201,8 +225,7 @@ index_short() {
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# if not parent offer to go up
|
# if not parent offer to go up
|
||||||
{ test "$dirbase" = "" } || {
|
[[ "$dir" = "" ]] || {
|
||||||
func "dirbase: $dirbase"
|
|
||||||
func "parent: $parent"
|
func "parent: $parent"
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
<tr>
|
<tr>
|
||||||
|
|
@ -220,7 +243,7 @@ EOF
|
||||||
for f in ${files}; do
|
for f in ${files}; do
|
||||||
name="${f}"
|
name="${f}"
|
||||||
ext="${name##*.}" # file extension
|
ext="${name##*.}" # file extension
|
||||||
file="${dir}/${name}" # file path
|
file="${archive}/${dir}/${name}" # file path
|
||||||
|
|
||||||
typefield=""
|
typefield=""
|
||||||
namefield=""
|
namefield=""
|
||||||
|
|
@ -232,24 +255,24 @@ EOF
|
||||||
if [ -L "$file" ]; then # is a symlink
|
if [ -L "$file" ]; then # is a symlink
|
||||||
if [ -d "$file" ]; then # symlink to folder
|
if [ -d "$file" ]; then # symlink to folder
|
||||||
func "$name folder symlink"
|
func "$name folder symlink"
|
||||||
link="<a href=\"${name}/index${EXTENSION}\">"
|
link="<a href=\"${url}/${dir}/${name}/index${EXTENSION}\">"
|
||||||
typefield="${link}<img src=\"${WEB_ROOT}/icons${THUMB_SIZE}/symlink.png\" alt=\"symlink\" ${icon_width}></a>"
|
typefield="${link}<img src=\"${url}/icons${THUMB_SIZE}/symlink.png\" alt=\"symlink\" ${icon_width}></a>"
|
||||||
namefield="${link}${name}</a>"
|
namefield="${link}${name}</a>"
|
||||||
else # symlink to file
|
else # symlink to file
|
||||||
func "$name file symlink"
|
func "$name file symlink"
|
||||||
link="<a href=\"${LINK_PREFIX}/${name}\">"
|
link="<a href=\"${data}/${dir}/${name}\">"
|
||||||
typefield="${link}<img src=\"${WEB_ROOT}/icons${THUMB_SIZE}/symlink.png\" alt=\"symlink\" ${icon_width}></a>"
|
typefield="${link}<img src=\"${WEB_ROOT}/icons${THUMB_SIZE}/symlink.png\" alt=\"symlink\" ${icon_width}></a>"
|
||||||
namefield="${link}${name}</a>"
|
namefield="${link}${name}</a>"
|
||||||
fi
|
fi
|
||||||
elif [ -d "$file" ]; then # is a folder
|
elif [ -d "$file" ]; then # is a folder
|
||||||
func "$name folder"
|
func "$name folder"
|
||||||
link="<a href=\"${name}/index${EXTENSION}\">"
|
link="<a href=\"${url}/${dir}/${name}/index${EXTENSION}\">"
|
||||||
typefield="${link}<img src=\"${WEB_ROOT}/icons${THUMB_SIZE}/folder.png\" alt=\"folder\" ${icon_width}></a>"
|
typefield="${link}<img src=\"${WEB_ROOT}/icons${THUMB_SIZE}/folder.png\" alt=\"folder\" ${icon_width}></a>"
|
||||||
namefield="${link}${name}</a>"
|
namefield="${link}${name}</a>"
|
||||||
else # is a file
|
else # is a file
|
||||||
func "$name file"
|
func "$name file"
|
||||||
{ test "$icon" = "" } && { icon="`filetype_icon ${file}`" }
|
{ test "$icon" = "" } && { icon="`filetype_icon ${file}`" }
|
||||||
link="<a href=\"${LINK_PREFIX}/${name}\">"
|
link="<a href=\"${data}/${dir}/${name}\">"
|
||||||
typefield="${link}<img src=\"${WEB_ROOT}/icons${THUMB_SIZE}/${icon}\" alt=\"${icon}\" ${icon_width}></a>"
|
typefield="${link}<img src=\"${WEB_ROOT}/icons${THUMB_SIZE}/${icon}\" alt=\"${icon}\" ${icon_width}></a>"
|
||||||
namefield="${link}${name}</a>"
|
namefield="${link}${name}</a>"
|
||||||
fi
|
fi
|
||||||
|
|
@ -278,8 +301,9 @@ EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
index_long_preview() {
|
index_long_preview() {
|
||||||
func "index_long_preview \"$1\""
|
|
||||||
dir="${1}"
|
dir="${1}"
|
||||||
|
func "index_long_preview \"$dir\""
|
||||||
|
|
||||||
{ test -d "$dir" } || { error "cannot index: not a directory '$dir'"; return 1 }
|
{ test -d "$dir" } || { error "cannot index: not a directory '$dir'"; return 1 }
|
||||||
files=()
|
files=()
|
||||||
ttmp=`ls -l --time-style=long-iso "$dir" | awk '
|
ttmp=`ls -l --time-style=long-iso "$dir" | awk '
|
||||||
|
|
@ -295,14 +319,6 @@ index_long_preview() {
|
||||||
|
|
||||||
act "${#files} files parsed in $dir"
|
act "${#files} files parsed in $dir"
|
||||||
|
|
||||||
dirbase="$1"
|
|
||||||
# setup paths for test
|
|
||||||
if [ "$CMD" = "test" ]; then
|
|
||||||
LINK_PREFIX="file://${dir}"
|
|
||||||
else
|
|
||||||
LINK_PREFIX="${urlsuffix}${dirbase}"
|
|
||||||
fi
|
|
||||||
func "LINK_PREFIX = $LINK_PREFIX"
|
|
||||||
|
|
||||||
# human size dividers
|
# human size dividers
|
||||||
_mb=$((1024 * 1024))
|
_mb=$((1024 * 1024))
|
||||||
|
|
@ -410,6 +426,9 @@ EOF
|
||||||
print "</table>"
|
print "</table>"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# preview_file() - takes a filename as arg
|
||||||
|
# renders the file in a usable format (thumb if image, html if markdown, etc.)
|
||||||
|
# returns the filename of the rendered result
|
||||||
preview_file() {
|
preview_file() {
|
||||||
{ test "$1" = "" } && { error "no file to preview."; return 1 }
|
{ test "$1" = "" } && { error "no file to preview."; return 1 }
|
||||||
# get the file extension using zsh builtins
|
# get the file extension using zsh builtins
|
||||||
|
|
@ -462,4 +481,3 @@ preview_file() {
|
||||||
done
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
5
init
5
init
|
|
@ -81,6 +81,11 @@ EXTENSION=".html"
|
||||||
# leave blank if relative, or for instance /blog/
|
# leave blank if relative, or for instance /blog/
|
||||||
WEB_ROOT=""
|
WEB_ROOT=""
|
||||||
|
|
||||||
|
# What is the url for files in case indexing is used
|
||||||
|
# this can be different from WEB_ROOT in order to serve
|
||||||
|
# files from a position different from the web pages
|
||||||
|
# FILES_ROOT=""
|
||||||
|
|
||||||
# Uncomment for Flowtype
|
# Uncomment for Flowtype
|
||||||
# FLOWTYPE=1
|
# FLOWTYPE=1
|
||||||
# What is the size ratio of text with respect to the width
|
# What is the size ratio of text with respect to the width
|
||||||
|
|
|
||||||
13
render
13
render
|
|
@ -45,7 +45,7 @@ WEB_ROOT=""
|
||||||
|
|
||||||
# prefix to all indexed files
|
# prefix to all indexed files
|
||||||
# this can be a full path on the filesystem
|
# this can be a full path on the filesystem
|
||||||
INDEX_PREFIX=""
|
FILES_ROOT=""
|
||||||
|
|
||||||
# thumbnail size
|
# thumbnail size
|
||||||
THUMB_SIZE=256
|
THUMB_SIZE=256
|
||||||
|
|
@ -74,7 +74,6 @@ destination="$DIR/pub"
|
||||||
|
|
||||||
# setup paths for test
|
# setup paths for test
|
||||||
{ test "$CMD" = "test" } && {
|
{ test "$CMD" = "test" } && {
|
||||||
LINK_PREFIX="file://`pwd`"
|
|
||||||
WEB_ROOT="file://`PWD=${SYS} pwd`/test"
|
WEB_ROOT="file://`PWD=${SYS} pwd`/test"
|
||||||
destination="$DIR/test"
|
destination="$DIR/test"
|
||||||
notice "Test settings for indexing"
|
notice "Test settings for indexing"
|
||||||
|
|
@ -440,16 +439,24 @@ idxs=(`find views -type f -name '*.idx'`)
|
||||||
idxs+=(`find views -type f -name '*.index'`)
|
idxs+=(`find views -type f -name '*.index'`)
|
||||||
{ test ${#idxs} = 0 } || {
|
{ test ${#idxs} = 0 } || {
|
||||||
source $SYS/index
|
source $SYS/index
|
||||||
|
# loop through all .idx files
|
||||||
for idx in $idxs; do
|
for idx in $idxs; do
|
||||||
|
# destination dir is named after the .idx file
|
||||||
dst=`calc_dest "$idx"`
|
dst=`calc_dest "$idx"`
|
||||||
# index always use dirs
|
# strip extension: an index builds a dir structure
|
||||||
dst="${dst%.*}"
|
dst="${dst%.*}"
|
||||||
notice "Directory index rendering to: $dst"
|
notice "Directory index rendering to: $dst"
|
||||||
|
# loop through all contents of the idx:
|
||||||
|
# one directory to index recursively on each line
|
||||||
dirs=`cat ${idx}`
|
dirs=`cat ${idx}`
|
||||||
for d in ${(f)dirs}; do
|
for d in ${(f)dirs}; do
|
||||||
mkdir -p "${dst}"
|
mkdir -p "${dst}"
|
||||||
pushd "${dst}"
|
pushd "${dst}"
|
||||||
|
# recursion wrap: $1=archive $2=diralias $3=indextype
|
||||||
recursive_index "${d[(ws: :)1]}" "${d[(ws: :)2]}" "${d[(ws: :)3]}"
|
recursive_index "${d[(ws: :)1]}" "${d[(ws: :)2]}" "${d[(ws: :)3]}"
|
||||||
|
# archive: full path where the files to be indexed are found
|
||||||
|
# diralias: index directory appended to url
|
||||||
|
# indextype: type of index (short | long)
|
||||||
popd
|
popd
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue