mirror of https://github.com/dyne/webnomad.git
several improvements to indexing and code cleanup
This commit is contained in:
parent
f73822ebe9
commit
27de3187cd
27
fonts
27
fonts
|
|
@ -1,38 +1,51 @@
|
|||
# prepare fonts
|
||||
|
||||
fonts=('Arial' 'Arial Black' 'Comic Sans MS' 'Courier New' 'Georgia' 'Impact' 'Monaco' 'Lucida Grande')
|
||||
fonts+=('Book Antiqua' 'Tahoma' 'Times New Roman' 'Trebuchet MS' 'Verdana' 'Geneva' 'New York')
|
||||
# fonts=('Arial' 'Arial Black' 'Comic Sans MS' 'Courier New' 'Georgia' 'Impact' 'Monaco' 'Lucida Grande')
|
||||
# fonts+=('Book Antiqua' 'Tahoma' 'Times New Roman' 'Trebuchet MS' 'Verdana' 'Geneva' 'New York')
|
||||
custom_fonts=()
|
||||
total_fonts=${#fonts}
|
||||
total_fonts=0 # ${#fonts}
|
||||
|
||||
# if there are custom fonts add them
|
||||
{ test -d fonts } && {
|
||||
notice "Indexing custom fonts"
|
||||
rm -f ${destination}/css/custom.fonts.css
|
||||
mkdir -p ${destination}/css
|
||||
|
||||
ttf=`find -L fonts -iname '*.ttf'`
|
||||
for f in ${(f)ttf}; do
|
||||
ffile=`basename "$f"`
|
||||
cp "$f" ${destination}/css/"$ffile"
|
||||
custom_fonts+=("${ffile%.ttf}")
|
||||
cat <<EOF >> ${destination}/css/custom.fonts.css
|
||||
@font-face { font-family: '${ffile%.ttf}';
|
||||
src: url('$ffile') format('truetype'); }
|
||||
@font-face { font-family: '${ffile%.ttf}';
|
||||
src: url('$ffile') format('truetype'); }
|
||||
EOF
|
||||
total_fonts=$(( $total_fonts + 1 ))
|
||||
done
|
||||
|
||||
otf=`find -L fonts -iname '*.otf'`
|
||||
for f in ${(f)otf}; do
|
||||
ffile=`basename "$f"`
|
||||
cp "$f" ${destination}/css/"$ffile"
|
||||
custom_fonts+=("${ffile%.otf}")
|
||||
cat <<EOF >> ${destination}/css/custom.fonts.css
|
||||
@font-face { font-family: '${ffile%.otf}';
|
||||
src: url('$ffile') format('opentype'); }
|
||||
@font-face { font-family: '${ffile%.otf}';
|
||||
src: url('$ffile') format('opentype'); }
|
||||
EOF
|
||||
total_fonts=$(( $total_fonts + 1 ))
|
||||
done
|
||||
|
||||
woff=`find -L fonts -iname '*.woff'`
|
||||
for f in ${(f)woff}; do
|
||||
ffile=`basename "$f"`
|
||||
cp "$f" ${destination}/css/"$ffile"
|
||||
custom_fonts+=("${ffile%.woff}")
|
||||
cat <<EOF >> ${destination}/css/custom.fonts.css
|
||||
@font-face { font-family: '${ffile%.woff}';
|
||||
src: url('$ffile') format('woff'); }
|
||||
EOF
|
||||
total_fonts=$(( $total_fonts + 1 ))
|
||||
done
|
||||
|
||||
act "$total_fonts custom fonts indexed"
|
||||
}
|
||||
|
|
|
|||
139
index
139
index
|
|
@ -59,6 +59,7 @@ filetype_icon() {
|
|||
sql) res=text-x-sql.png ;;
|
||||
vcart) res=text-x-vcard.png ;;
|
||||
dmg) res=dmg.png ;;
|
||||
pdf) res=application-pdf.png ;;
|
||||
esac
|
||||
# analize name
|
||||
case $name:l in
|
||||
|
|
@ -79,46 +80,142 @@ filetype_icon() {
|
|||
print "$res"
|
||||
}
|
||||
|
||||
|
||||
# should be called from inside the destination directory
|
||||
recursive_index() {
|
||||
# render_header "<link rel=\"stylesheet\" href=\"css/blueimp-gallery.min.css\" />"
|
||||
{ test -d "$1" } || { error "cannot index directory not found: $1"; return 1 }
|
||||
|
||||
archive="$1"
|
||||
dirs=`find "$archive" -type d`
|
||||
basedir="/`basename "$archive"`/"
|
||||
|
||||
diralias="$2"
|
||||
|
||||
indextype="$3"
|
||||
|
||||
dest="`pwd`"
|
||||
|
||||
func "index archive $archive"
|
||||
func "index basedir: $basedir"
|
||||
func "index aliasdir: $diralias"
|
||||
# copy default icons
|
||||
mkdir -p $destination/icons$THUMB_SIZE
|
||||
cp $SYS/icons/$THUMB_SIZE/image-x-generic.png $destination/icons$THUMB_SIZE
|
||||
cp $SYS/icons/$THUMB_SIZE/symlink.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
|
||||
|
||||
for d in ${(f)dirs}; do
|
||||
dir="${d##*${basedir}}"
|
||||
func "actual file path: $d"
|
||||
func "relative path: $dir"
|
||||
func "destination: ${dest}/${dir}"
|
||||
|
||||
mkdir -p "${dest}/${dir}"
|
||||
pushd "${dest}/${dir}"
|
||||
|
||||
render_header > index${EXTENSION}
|
||||
render_file "$DIR"/tmpl/navbar.html >> index${EXTENSION}
|
||||
cat <<EOF >> index${EXTENSION}
|
||||
<div class="container-fluid">
|
||||
<article>
|
||||
EOF
|
||||
|
||||
# if indextype ends in _readme then renders README besides
|
||||
[[ "$indextype" =~ "readme" ]] && {
|
||||
test -r "${d}/README" } && {
|
||||
print "<div class=\"span4\">" >> index${EXTENSION} }
|
||||
|
||||
# takes 3 arguments: base dir, alias dir and indexed directory
|
||||
# we must check if its the parent directory
|
||||
index_${indextype%_readme*} "${archive}" "${diralias}" "${dir}" >> index${EXTENSION}
|
||||
# here also strips the _readme modifier
|
||||
|
||||
[[ "$indextype" =~ "readme" ]] && {
|
||||
test -r "${d}/README" } && {
|
||||
|
||||
print "</div><div class=\"span6\"><pre>" >> index${EXTENSION}
|
||||
cat "${d}/README" >> index${EXTENSION}
|
||||
|
||||
print "</pre></div>" >> index${EXTENSION}
|
||||
}
|
||||
|
||||
cat <<EOF >> index${EXTENSION}
|
||||
</article>
|
||||
</div>
|
||||
<p> </p>
|
||||
EOF
|
||||
|
||||
render_footer >> index${EXTENSION}
|
||||
|
||||
popd
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
index_short() {
|
||||
func "index_long_preview \"$1\" \"$2\" \"$3\""
|
||||
func "index_short \"$1\" \"$2\" \"$3\""
|
||||
dir="${1}${3}"
|
||||
{ test -d "$dir" } || { error "cannot index: not a directory '$dir'"; return 1 }
|
||||
files=()
|
||||
ttmp=`ls "$dir" | awk '
|
||||
ttmp=`ls -l --time-style=long-iso "$dir" | awk '
|
||||
/^total/ { next }
|
||||
/^$/ { next }
|
||||
{ printf "files+=(\"$1\");" }
|
||||
/'"index${EXTENSION}"'/ { next }
|
||||
{ printf "files+=(\"%s\");", $8 }
|
||||
'`
|
||||
{ test $? = 0 } || {
|
||||
error "Error parsing directory: $dir"
|
||||
return 1 }
|
||||
|
||||
func "$ttmp"
|
||||
eval "$ttmp"
|
||||
|
||||
act "${#files} files parsed in $dir"
|
||||
|
||||
diralias="$2"
|
||||
dirbase="$3"
|
||||
|
||||
# setup paths for test
|
||||
if [ "$CMD" = "test" ]; then
|
||||
LINK_PREFIX="file://${dir}"
|
||||
tpwd=`pwd`
|
||||
parent="${tpwd%/*}"
|
||||
else
|
||||
LINK_PREFIX="${diralias}${dirbase}"
|
||||
parent=".."
|
||||
fi
|
||||
func "LINK_PREFIX = $LINK_PREFIX"
|
||||
|
||||
cat <<EOF
|
||||
<table class="table table-hover table-condensed">
|
||||
<thead><tr>
|
||||
<th class="col-sm-1 col-md-1 col-lg-1"><!-- filetype icon --></th>
|
||||
<th class="col-sm-3 col-md-4 col-lg-4"><!-- file name --></th>
|
||||
<th style="width:100px"><!-- filetype icon --></th>
|
||||
<th><!-- file name --></th>
|
||||
</tr></thead>
|
||||
EOF
|
||||
|
||||
# if not parent offer to go up
|
||||
{ test "$dirbase" = "" } || {
|
||||
func "dirbase: $dirbase"
|
||||
func "parent: $parent"
|
||||
cat <<EOF
|
||||
<tr>
|
||||
<td style="vertical-align:middle;">
|
||||
<a href="${parent}/index${EXTENSION}">
|
||||
<img src="${WEB_ROOT}/icons${THUMB_SIZE}/go-up.png"
|
||||
alt="parent directory" title="go to parent"></a></td>
|
||||
<td style="vertical-align:middle;font-size:1.5em;word-wrap:break-word">
|
||||
<a href="${parent}/index${EXTENSION}">
|
||||
.. [ parent ]</a></td>
|
||||
</tr>
|
||||
EOF
|
||||
}
|
||||
|
||||
for f in ${files}; do
|
||||
name="${f}"
|
||||
ext="${name##*.}" # file extension
|
||||
file="${1}/${name}" # file path
|
||||
file="${dir}/${name}" # file path
|
||||
|
||||
typefield=""
|
||||
namefield=""
|
||||
|
|
@ -129,22 +226,26 @@ EOF
|
|||
|
||||
if [ -L "$file" ]; then # is a symlink
|
||||
if [ -d "$file" ]; then # symlink to folder
|
||||
func "$name folder symlink"
|
||||
link="<a href=\"${name}/index${EXTENSION}\">"
|
||||
typefield="${link}<img src=\"${WEB_ROOT}/icons/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>"
|
||||
else # symlink to file
|
||||
func "$name file symlink"
|
||||
link="<a href=\"${LINK_PREFIX}/${name}\">"
|
||||
typefield="${link}<img src=\"${WEB_ROOT}/icons/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>"
|
||||
fi
|
||||
elif [ -d "$file" ]; then # is a folder
|
||||
func "$name folder"
|
||||
link="<a href=\"${name}/index${EXTENSION}\">"
|
||||
typefield="${link}<img src=\"${WEB_ROOT}/icons/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>"
|
||||
else # is a file
|
||||
func "$name file"
|
||||
{ test "$icon" = "" } && { icon="`filetype_icon ${file}`" }
|
||||
link="<a href=\"${LINK_PREFIX}/${name}\">"
|
||||
typefield="${link}<img src=\"${WEB_ROOT}/icons/${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>"
|
||||
fi
|
||||
|
||||
|
|
@ -159,10 +260,10 @@ EOF
|
|||
{ test "$icon" = "" } && { continue }
|
||||
popd
|
||||
# copy the icon file
|
||||
{ test -r ${destination}/icons/${icon} } || {
|
||||
{ test -r ${destination}/icons${THUMB_SIZE}/${icon} } || {
|
||||
func "copy icon in place: $icon (PWD: `pwd`)"
|
||||
cp $SYS/icons/$THUMB_SIZE/${icon} \
|
||||
${destination}/icons/${icon}
|
||||
${destination}/icons${THUMB_SIZE}/${icon}
|
||||
}
|
||||
pushd "$tpwd"
|
||||
|
||||
|
|
@ -257,24 +358,24 @@ EOF
|
|||
if [ -L "$file" ]; then # is a symlink
|
||||
if [ -d "$file" ]; then # symlink to folder
|
||||
link="<a href=\"${name}/index${EXTENSION}\">"
|
||||
typefield="${link}<img src=\"${WEB_ROOT}/icons/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>"
|
||||
previewfield="<!-- folder -->"
|
||||
else # symlink to file
|
||||
link="<a href=\"${LINK_PREFIX}/${name}\">"
|
||||
typefield="${link}<img src=\"${WEB_ROOT}/icons/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>"
|
||||
previewfield="${link}${preview}</a>"
|
||||
fi
|
||||
elif [ -d "$file" ]; then # is a folder
|
||||
link="<a href=\"${name}/index${EXTENSION}\">"
|
||||
typefield="${link}<img src=\"${WEB_ROOT}/icons/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>"
|
||||
previewfield="<!-- folder -->"
|
||||
else # is a file
|
||||
{ test "$icon" = "" } && { icon="`filetype_icon ${file}`" }
|
||||
link="<a href=\"${LINK_PREFIX}/${name}\">"
|
||||
typefield="${link}<img src=\"${WEB_ROOT}/icons/${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>"
|
||||
previewfield="${link}${preview}</a>"
|
||||
fi
|
||||
|
|
@ -294,10 +395,10 @@ EOF
|
|||
{ test "$icon" = "" } && { continue }
|
||||
popd
|
||||
# copy the icon file
|
||||
{ test -r ${destination}/icons/${icon} } || {
|
||||
{ test -r ${destination}/icons${THUMB_SIZE}/${icon} } || {
|
||||
func "copy icon in place: $icon (PWD: `pwd`)"
|
||||
cp $SYS/icons/$THUMB_SIZE/${icon} \
|
||||
${destination}/icons/${icon}
|
||||
${destination}/icons${THUMB_SIZE}/${icon}
|
||||
}
|
||||
pushd "$tpwd"
|
||||
|
||||
|
|
|
|||
38
init
38
init
|
|
@ -32,41 +32,37 @@ act
|
|||
|
||||
mkdir -p views/js
|
||||
mkdir -p views/css
|
||||
touch views/css/custom.css
|
||||
|
||||
{ test -r views/index.html } || {
|
||||
cat <<EOF > views/index.html
|
||||
<h1>Hello world</h1>
|
||||
|
||||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
|
||||
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad
|
||||
minim veniam, quis nostrud exercitation ullamco laboris nisi ut
|
||||
aliquip ex ea commodo consequat. Duis aute irure dolor in
|
||||
reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla
|
||||
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
|
||||
culpa qui officia deserunt mollit anim id est laborum.</p>
|
||||
eiusmod tempor incididunt ut labore et dolore magna aliqua.
|
||||
</p>
|
||||
|
||||
<blockquote>Ut enim ad minim veniam, quis nostrud exercitation ullamco
|
||||
laboris nisi ut aliquip ex ea commodo consequat.</blockquote>
|
||||
|
||||
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum
|
||||
dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
|
||||
proident, sunt in culpa qui officia deserunt mollit anim id est
|
||||
laborum.</p>
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
mkdir -p tmpl
|
||||
{ test -r tmpl/header.html } || {
|
||||
cp -v ${SYS}/tmpl/header.html tmpl }
|
||||
cp -v ${SYS}/tmpl/header.html tmpl/ }
|
||||
|
||||
{ test -r tmpl/footer.html } || {
|
||||
cp -v ${SYS}/tmpl/footer.html tmpl }
|
||||
cp -v ${SYS}/tmpl/footer.html tmpl/ }
|
||||
|
||||
{ test -r tmpl/navbar.html } || {
|
||||
cp -v ${SYS}/tmpl/navbar.html tmpl }
|
||||
cp -v ${SYS}/tmpl/navbar.html tmpl/ }
|
||||
|
||||
{ test -r views/js/html5.js } || {
|
||||
cp -v ${SYS}/js/html5.js views/js }
|
||||
|
||||
{ test -r views/css/bootstrap.css } || {
|
||||
cp -v ${SYS}/js/bootstrap* views/js
|
||||
cp -v ${SYS}/css/bootstrap* views/css }
|
||||
|
||||
{ test -r views/css/blueimp-gallery.css } || {
|
||||
cp -v ${SYS}/js/*blueimp* views/js
|
||||
cp -v ${SYS}/css/*blueimp* views/css }
|
||||
|
||||
{ test -r config.zsh } || {
|
||||
cat <<EOF > config.zsh
|
||||
|
|
@ -85,10 +81,6 @@ EXTENSION=".html"
|
|||
# leave blank if relative, or for instance /blog/
|
||||
WEB_ROOT=""
|
||||
|
||||
# where on the server filesystem are the indexed files located
|
||||
# this directory should be aliased by apache
|
||||
INDEX_PREFIX=""
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
|
|||
204
render
204
render
|
|
@ -39,13 +39,6 @@ CMD="$1"
|
|||
####################################
|
||||
# Base configuration
|
||||
|
||||
# base to be added to all urls
|
||||
# used by test to have all css and js in place
|
||||
baseurl=""
|
||||
|
||||
# destination directory to render
|
||||
# also used by test to substitute pub/
|
||||
destination="pub"
|
||||
|
||||
# web root for all urls
|
||||
WEB_ROOT=""
|
||||
|
|
@ -60,7 +53,8 @@ THUMB_SIZE=256
|
|||
source config.zsh
|
||||
####################################
|
||||
|
||||
typeset -h dst # full path to destination for render_ functions
|
||||
typeset -h dst
|
||||
|
||||
typeset -alU includecss # array of css files to include
|
||||
typeset -alU includejs # array of js files to include
|
||||
typeset -alU fonts # array of available fonts
|
||||
|
|
@ -71,17 +65,24 @@ unsetopt CASE_GLOB
|
|||
notice "Rendering your website"
|
||||
act "Title: $B $TITLE $r"
|
||||
|
||||
# destination directory to render
|
||||
# also used by test to substitute pub/
|
||||
destination="$DIR/pub"
|
||||
|
||||
# setup paths for test
|
||||
{ test "$CMD" = "test" } && {
|
||||
LINK_PREFIX="file://`pwd`"
|
||||
WEB_ROOT="file://`PWD=${SYS} pwd`/test"
|
||||
baseurl="$WEB_ROOT"
|
||||
destination="$DIR/test"
|
||||
notice "Test settings for indexing"
|
||||
act "SYS = $SYS"
|
||||
act "WEB_ROOT = $WEB_ROOT"
|
||||
}
|
||||
|
||||
# base to be added to all urls, from config.zsh
|
||||
baseurl="$WEB_ROOT"
|
||||
|
||||
act "SYS = $SYS"
|
||||
act "WEB_ROOT = $WEB_ROOT"
|
||||
|
||||
render_file() { sed -e "s@\${baseurl}@${baseurl}@g" $@ }
|
||||
|
||||
render_header() {
|
||||
|
|
@ -105,26 +106,27 @@ render_header() {
|
|||
|
||||
<!-- Bootstrap -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link href="${baseurl}css/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="${baseurl}/css/bootstrap.min.css" rel="stylesheet" />
|
||||
<link href="${baseurl}/css/bootstrap-responsive.min.css" rel="stylesheet" />
|
||||
|
||||
EOF
|
||||
{ test -r "$DIR"/views/css/custom.css } && {
|
||||
cat <<EOF
|
||||
<link href="${baseurl}css/custom.css" rel="stylesheet" />
|
||||
<link href="${baseurl}/css/custom.css" rel="stylesheet" />
|
||||
EOF
|
||||
}
|
||||
|
||||
# add css needed for internal functions
|
||||
for c in $includecss; do
|
||||
cat <<EOF
|
||||
<link href="${baseurl}css/${c}" rel="stylesheet" />
|
||||
<link href="${baseurl}/css/${c}" rel="stylesheet" />
|
||||
EOF
|
||||
cp "$SYS"/css/${c} "${destination}"/css/
|
||||
done
|
||||
|
||||
{ test -f "${destination}"/css/custom.fonts.css } && {
|
||||
cat <<EOF
|
||||
<link href="${baseurl}css/custom.fonts.css" rel="stylesheet" />
|
||||
<link href="${baseurl}/css/custom.fonts.css" rel="stylesheet" />
|
||||
EOF
|
||||
}
|
||||
|
||||
|
|
@ -137,12 +139,12 @@ EOF
|
|||
}
|
||||
|
||||
render_footer() {
|
||||
render_file "$DIR"/tmpl/footer.html
|
||||
|
||||
cat <<EOF
|
||||
</div><!--/.container-->
|
||||
EOF
|
||||
|
||||
render_file "$DIR"/tmpl/footer.html
|
||||
|
||||
# add any string argument to the footer
|
||||
{ test "$1" = "" } || { print "${@}"; print }
|
||||
|
||||
|
|
@ -156,8 +158,7 @@ EOF
|
|||
done
|
||||
|
||||
# if test mode then render the test footer
|
||||
{ test "$destination" = "test" } && {
|
||||
render_test_footer }
|
||||
{ test "$CMD" = "test" } && { render_test_footer }
|
||||
|
||||
cat <<EOF
|
||||
</body>
|
||||
|
|
@ -216,64 +217,6 @@ render_html() {
|
|||
|
||||
}
|
||||
|
||||
# should be called from inside the destination directory
|
||||
recursive_index() {
|
||||
# render_header "<link rel=\"stylesheet\" href=\"css/blueimp-gallery.min.css\" />"
|
||||
{ test -d "$1" } || { error "cannot index directory not found: $1"; return 1 }
|
||||
|
||||
archive="$1"
|
||||
dirs=`find "$archive" -type d`
|
||||
basedir="/`basename "$archive"`/"
|
||||
|
||||
diralias="$2"
|
||||
|
||||
dest="`pwd`"
|
||||
|
||||
func "index archive $archive"
|
||||
func "index basedir: $basedir"
|
||||
func "index aliasdir: $diralias"
|
||||
# copy default icons
|
||||
mkdir -p $destination/icons
|
||||
cp $SYS/icons/$THUMB_SIZE/image-x-generic.png $destination/icons
|
||||
cp $SYS/icons/$THUMB_SIZE/symlink.png $destination/icons
|
||||
cp $SYS/icons/$THUMB_SIZE/folder.png $destination/icons
|
||||
|
||||
for d in ${(f)dirs}; do
|
||||
dir="${d##*${basedir}}"
|
||||
func "actual file path: $d"
|
||||
func "relative path: $dir"
|
||||
func "destination: ${dest}/${dir}"
|
||||
|
||||
mkdir -p "${dest}/${dir}"
|
||||
pushd "${dest}/${dir}"
|
||||
|
||||
render_header > index${EXTENSION}
|
||||
render_file "$DIR"/tmpl/navbar.html >> index${EXTENSION}
|
||||
cat <<EOF >> index${EXTENSION}
|
||||
<div class="container">
|
||||
<article>
|
||||
EOF
|
||||
|
||||
# takes 3 arguments: base dir, alias dir and indexed directory
|
||||
# we must check if its the parent directory
|
||||
index_long_preview "${archive}" "${diralias}" "${dir}" >> index${EXTENSION}
|
||||
# if [ "$dir" = "" ]; then
|
||||
# index_dir "${d}" "${diralias}" "" >> index${EXTENSION}
|
||||
# else
|
||||
# index_dir "${d%%${dir}*}" "${diralias}" "${dir}" >> index${EXTENSION}
|
||||
# fi
|
||||
cat <<EOF >> index${EXTENSION}
|
||||
</article>
|
||||
</div>
|
||||
<p> </p>
|
||||
EOF
|
||||
|
||||
render_footer >> index${EXTENSION}
|
||||
|
||||
popd
|
||||
done
|
||||
}
|
||||
|
||||
read_meta() {
|
||||
tmp=`head -n 3 | awk '
|
||||
!/^#/ { next }
|
||||
|
|
@ -284,23 +227,61 @@ read_meta() {
|
|||
eval "$tmp"
|
||||
}
|
||||
|
||||
# calculate the destination path for a file or folder to render from views
|
||||
calc_dest() {
|
||||
{ test -r "$1" } || {
|
||||
error "error calculating destination: cannot read $1"
|
||||
return 0 }
|
||||
# optional 2nd arg: extension
|
||||
ext="$2"
|
||||
{ test "$ext" = "" } && { ext="$EXTENSION" }
|
||||
|
||||
func "calc_dest \"$1\" \"$2\""
|
||||
|
||||
dstfile=${1##*/}
|
||||
dstfile=${dstfile%.*}${ext}
|
||||
func "destination file: $dstfile"
|
||||
dstdir=${1##*views/}
|
||||
dstdir=${dstdir%/*}
|
||||
func "destination subdir: $dstdir"
|
||||
|
||||
# compute destination file
|
||||
if [ "${dstfile%.*}" = "${dstdir%.*}" ]; then
|
||||
# no subdirs, root level
|
||||
dst="${destination}/${dstfile}"
|
||||
else
|
||||
dst="${destination}/${dstdir}/${dstfile}"
|
||||
mkdir -p ${destination}/${dstdir}
|
||||
fi
|
||||
func "calculated destination: $dst"
|
||||
print $dst
|
||||
}
|
||||
|
||||
#########
|
||||
# MAIN
|
||||
|
||||
{ test "$1" = "source" } && { return 0 }
|
||||
{ test "$1" = "test" } && {
|
||||
act "Local test rendering inside test/"
|
||||
source $SYS/test }
|
||||
|
||||
# copy core bootstrap files in place
|
||||
mkdir -p "$destination/css"
|
||||
mkdir -p "$destination/js"
|
||||
|
||||
{ test -r "$destination"/css/bootstrap.css } || {
|
||||
cp "$SYS"/css/bootstrap.css "$destination"/css/
|
||||
cp "$SYS"/css/bootstrap.min.css "$destination"/css/
|
||||
cp "$SYS"/css/bootstrap-responsive.css "$destination"/css/
|
||||
}
|
||||
cp "$SYS"/js/bootstrap.min.js "$destination"/js/
|
||||
cp "$SYS"/js/html5.js "$destination"/js/
|
||||
|
||||
|
||||
|
||||
# prepare all fonts
|
||||
source $SYS/fonts
|
||||
|
||||
# Main
|
||||
mkdir -p ${destination}/css
|
||||
mkdir -p ${destination}/js
|
||||
|
||||
cat << EOF > ${destination}/.htaccess
|
||||
DirectoryIndex index index.html index.php
|
||||
DefaultType text/html
|
||||
EOF
|
||||
|
||||
act -n "Clean up all temp files ... "
|
||||
temps=(`find "$destination" -type f -name 'temp-*'`)
|
||||
|
|
@ -312,7 +293,7 @@ print "done"
|
|||
txts=(`find views -maxdepth 1 -type f -name '*.txt'`)
|
||||
for t in $txts; do
|
||||
txt=`basename $t`
|
||||
dst="${destination}/$txt"
|
||||
dst=`calc_dest "$t" .txt`
|
||||
act "publishing plain text: $txt"
|
||||
cp $t ${destination}/$txt
|
||||
done
|
||||
|
|
@ -324,8 +305,7 @@ for src in $htmls; do
|
|||
# read meta commands
|
||||
cat ${src} | read_meta
|
||||
|
||||
# compute destination file
|
||||
dst="${destination}/`basename ${src%.*}`${EXTENSION}"
|
||||
dst=`calc_dest "$src"`
|
||||
|
||||
render_header > $dst
|
||||
|
||||
|
|
@ -334,7 +314,6 @@ for src in $htmls; do
|
|||
</head> <!-- end of <head> -->
|
||||
|
||||
<body>
|
||||
<div class="container">
|
||||
EOF
|
||||
|
||||
# don't forget the navbar
|
||||
|
|
@ -342,6 +321,7 @@ EOF
|
|||
|
||||
cat <<EOF >> $dst
|
||||
<p> </p>
|
||||
<div class="container-fluid">
|
||||
<article>
|
||||
EOF
|
||||
|
||||
|
|
@ -363,45 +343,53 @@ EOF
|
|||
|
||||
done
|
||||
|
||||
|
||||
# render all image galleries
|
||||
source $SYS/gallery
|
||||
gals=(`find views -type f -name '*.gal'`)
|
||||
gals+=(`find views -type f -name '*.gallery'`)
|
||||
for src in $gals; do
|
||||
cat ${src} | read_meta
|
||||
dst="${destination}/`basename ${src%.*}`"
|
||||
act -n "Gallery rendering: $B $dst $r ... "
|
||||
cat $src | render_gallery > $dst
|
||||
print "done"
|
||||
done
|
||||
if [[ "${#gals}" > 0 ]]; then
|
||||
|
||||
cp "$SYS"/js/*blueimp* "$destination"/js/
|
||||
cp "$SYS"/css/*blueimp* "$destination"/css/
|
||||
cp "$SYS"/js/jquery.min.js "$destination"/js/
|
||||
|
||||
for src in $gals; do
|
||||
cat ${src} | read_meta
|
||||
dst=`calc_dest "$src"`
|
||||
act -n "Gallery rendering: $B $dst $r ... "
|
||||
cat $src | render_gallery > $dst
|
||||
print "done"
|
||||
done
|
||||
|
||||
fi
|
||||
|
||||
# render all directory indexes
|
||||
idxs=(`find views -type f -name '*.idx'`)
|
||||
idxs+=(`find views -type f -name '*.index'`)
|
||||
{ test ${#idxs} = 0 } || {
|
||||
source "$SYS/index"
|
||||
source $SYS/index
|
||||
for idx in $idxs; do
|
||||
dst=`basename ${idx%%.*}`
|
||||
dst=`calc_dest "$idx"`
|
||||
# index always use dirs
|
||||
dst="${dst%.*}"
|
||||
notice "Directory index rendering to: $dst"
|
||||
dirs=`cat ${idx}`
|
||||
for d in ${(f)dirs}; do
|
||||
mkdir -p "${destination}/${dst}"
|
||||
pushd "${destination}/${dst}"
|
||||
recursive_index "${d[(ws: :)1]}" "${d[(ws: :)2]}"
|
||||
mkdir -p "${dst}"
|
||||
pushd "${dst}"
|
||||
recursive_index "${d[(ws: :)1]}" "${d[(ws: :)2]}" "${d[(ws: :)3]}"
|
||||
popd
|
||||
done
|
||||
done
|
||||
# copy icons only if needed
|
||||
rsync -rlt "$SYS/icons" "${destination}/"
|
||||
}
|
||||
|
||||
# copy to destination all subdirs in views/
|
||||
for m in `find views -mindepth 1 -type d `; do
|
||||
act -n "publishing $B $m $r ... "
|
||||
rsync -r $m ${destination}/
|
||||
print "done"
|
||||
done
|
||||
act -n "publishing all $B views $r ... "
|
||||
rsync -a -W --ignore-existing "$DIR/views/" "${destination}/"
|
||||
# make sure that new css styles are updates
|
||||
cp -f "$DIR/views/css/custom.css" "${destination}/css/"
|
||||
print "done"
|
||||
|
||||
# if the whole website is a "slideshow" (set in config.zsh) then we start with
|
||||
# a full screen slideshow of all uploaded photos, cycling random every time.
|
||||
|
|
|
|||
5
theme
5
theme
|
|
@ -70,6 +70,7 @@ themedesc[united]="light, white background, sans, orange block menus"
|
|||
}
|
||||
|
||||
notice "Installing theme: $1"
|
||||
cp ${DIR}/themes/$1/bootstrap.min.css \
|
||||
views/css/bootstrap.min.css
|
||||
cp -v ${DIR}/themes/$1/bootstrap.min.css views/css/bootstrap.min.css
|
||||
cp -v ${DIR}/themes/$1/bootstrap.min.css test/css/bootstrap.min.css
|
||||
|
||||
exit 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue