mirror of https://github.com/dyne/webnomad.git
inline <markdown> rendering
semplified views input with possibility to embed markdown syntax various improvements and cleanups
This commit is contained in:
parent
32d39df6d0
commit
0647a0fac8
27
init
27
init
|
|
@ -51,25 +51,16 @@ mkdir -p tmpl
|
||||||
cp -v jaroweb/js/html5.js views/js }
|
cp -v jaroweb/js/html5.js views/js }
|
||||||
|
|
||||||
{ test -r views/css/bootstrap.css } || {
|
{ test -r views/css/bootstrap.css } || {
|
||||||
notice "Downloading and installing Bootstrap"
|
cp -v jaroweb/js/bootstrap* views/js
|
||||||
curl http://twitter.github.io/bootstrap/assets/bootstrap.zip -o bootstrap.zip
|
cp -v jaroweb/css/bootstrap* views/css }
|
||||||
unzip -q bootstrap.zip
|
|
||||||
rsync -r bootstrap/css views/
|
|
||||||
rsync -r bootstrap/js views/
|
|
||||||
rsync -r bootstrap/img views/
|
|
||||||
rm -rf bootstrap bootstrap.zip
|
|
||||||
act "Bootstrap installed"
|
|
||||||
}
|
|
||||||
|
|
||||||
{ test -r views/css/blueimp-gallery.js } || {
|
{ test -r views/css/blueimp-gallery.css } || {
|
||||||
notice "Downloading and installing BlueImp gallery"
|
cp -v jaroweb/js/*blueimp* views/js
|
||||||
git clone https://github.com/blueimp/Gallery.git blueimp
|
cp -v jaroweb/css/*blueimp* views/css }
|
||||||
rsync -r blueimp/css views/
|
|
||||||
rsync -r blueimp/js views/
|
{ test -r views/css/strapdown.css } || {
|
||||||
rsync -r blueimp/img views/
|
cp -v jaroweb/js/strapdown.js views/js
|
||||||
rm -rf blueimp
|
cp -v jaroweb/css/strapdown.css views/css }
|
||||||
act "BlueImp installed"
|
|
||||||
}
|
|
||||||
|
|
||||||
{ test -r config.zsh } || {
|
{ test -r config.zsh } || {
|
||||||
cat <<EOF > config.zsh
|
cat <<EOF > config.zsh
|
||||||
|
|
|
||||||
232
render
232
render
|
|
@ -34,11 +34,6 @@ act "Title: $TITLE"
|
||||||
|
|
||||||
typeset -a includejs
|
typeset -a includejs
|
||||||
|
|
||||||
mkdir -p pub
|
|
||||||
cat << EOF > pub/.htaccess
|
|
||||||
DirectoryIndex index index.html index.php
|
|
||||||
DefaultType text/html
|
|
||||||
EOF
|
|
||||||
|
|
||||||
render_header() {
|
render_header() {
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
@ -65,6 +60,12 @@ render_header() {
|
||||||
<link href="css/bootstrap-responsive.min.css" rel="stylesheet" />
|
<link href="css/bootstrap-responsive.min.css" rel="stylesheet" />
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
{ test -r views/css/style.css } && {
|
||||||
|
cat <<EOF
|
||||||
|
<link href="css/style.css" rel="stylesheet" />
|
||||||
|
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
{ test "$1" = "" } || { echo "${@}"; echo }
|
{ test "$1" = "" } || { echo "${@}"; echo }
|
||||||
|
|
||||||
|
|
@ -102,89 +103,48 @@ EOF
|
||||||
|
|
||||||
render_html() {
|
render_html() {
|
||||||
|
|
||||||
src=`find views -type f -name "${1}.html"`
|
|
||||||
|
|
||||||
{ test -r "${src}" } || {
|
#######################################
|
||||||
print "${1} section not found";
|
## we support the <markdown> tag inline
|
||||||
return 1 }
|
|
||||||
|
|
||||||
|
tmp="tmp.$RANDOM"
|
||||||
|
awk 'BEGIN { srand(); markdown=0; }
|
||||||
|
/^<markdown>/ { markdown=1; out="tmp.md" rand(); print out; next }
|
||||||
|
/^<\/markdown>/ { markdown=0; next }
|
||||||
|
{ if(markdown==1) { print $0 >out; next } else { print $0 } }
|
||||||
|
' > $tmp
|
||||||
|
|
||||||
dst="pub/${1}"
|
# first pass marks the markdown parts and saves them separate
|
||||||
|
|
||||||
act -n "rendering html: $dst... "
|
mds=(`find . -name 'tmp.md*'`)
|
||||||
# TODO: check duplicates
|
act -n "${#mds} markdown fields "
|
||||||
|
|
||||||
# establish if we are rendering a section
|
{ test ${#mds} = 0 } || {
|
||||||
if [[ ${sections[(i)$1]} -le ${#sections} ]]; then
|
# second pass substituted saved parts with rendered markdown
|
||||||
sec=${1}
|
|
||||||
else
|
|
||||||
sec=`dirname $src`
|
|
||||||
sec=${sec[(ws:/:)2]}
|
|
||||||
fi
|
|
||||||
|
|
||||||
render_header > $dst
|
for i in $mds; do
|
||||||
|
md=`basename $i`
|
||||||
echo "<article>" >> $dst
|
newtemp="tmp.$RANDOM"
|
||||||
grep -v '^#' ${src} >> $dst
|
cat $tmp | awk '
|
||||||
echo "</article>" >> $dst
|
/^'"$md"'/ { system("cat '"$md"' | markdown"); next }
|
||||||
|
{ print $0; }' > $newtemp
|
||||||
includejs+=(js/bootstrap.min.js)
|
rm $tmp; tmp=$newtemp
|
||||||
render_footer >> $dst
|
done
|
||||||
|
|
||||||
print "done."
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render_markdown() {
|
cat $tmp
|
||||||
src=`find views -type f -name "${1}.md"`
|
|
||||||
|
|
||||||
{ test -r "${src}" } || {
|
# clean up from temporary files
|
||||||
print "${1} section not found";
|
rm -f tmp.*
|
||||||
return 1 }
|
|
||||||
|
|
||||||
|
|
||||||
dst="pub/${1%.*}"
|
|
||||||
|
|
||||||
act -n "rendering markdown: $dst... "
|
|
||||||
# TODO: check duplicates
|
|
||||||
|
|
||||||
# establish if we are rendering a section
|
|
||||||
if [[ ${sections[(i)$1]} -le ${#sections} ]]; then
|
|
||||||
sec=${1}
|
|
||||||
else
|
|
||||||
sec=`dirname $src`
|
|
||||||
sec=${sec[(ws:/:)2]}
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
render_header > $dst
|
|
||||||
|
|
||||||
echo "<article>" >> $dst
|
|
||||||
cat ${src} | markdown >> $dst
|
|
||||||
echo "</article>" >> $dst
|
|
||||||
|
|
||||||
includejs+=(js/bootstrap.min.js)
|
|
||||||
render_footer >> $dst
|
|
||||||
|
|
||||||
print "done."
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render_gallery() {
|
render_gallery() {
|
||||||
src=`find views -type f -name "${1}.gal"`
|
|
||||||
|
|
||||||
{ test -r "${src}" } || {
|
render_header "<link rel=\"stylesheet\" href=\"css/blueimp-gallery.min.css\" />"
|
||||||
print "${1} section not found";
|
|
||||||
return 1 }
|
|
||||||
|
|
||||||
|
cat <<EOF
|
||||||
dst="pub/${1%.*}"
|
|
||||||
|
|
||||||
act -n "rendering gallery: $dst... "
|
|
||||||
|
|
||||||
render_header "<link rel=\"stylesheet\" href=\"css/blueimp-gallery.min.css\" />" > $dst
|
|
||||||
|
|
||||||
cat <<EOF >> $dst
|
|
||||||
<!-- The Gallery as lightbox dialog, should be a child element of the document body -->
|
<!-- The Gallery as lightbox dialog, should be a child element of the document body -->
|
||||||
<div id="blueimp-gallery" class="blueimp-gallery">
|
<div id="blueimp-gallery" class="blueimp-gallery">
|
||||||
<div class="slides"></div>
|
<div class="slides"></div>
|
||||||
|
|
@ -198,29 +158,31 @@ cat <<EOF >> $dst
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# embed the first slide into the page for non-javascript browsers
|
# put a notice for non-javascript browsers
|
||||||
nojs_line=`grep -v '^#' ${src} | head -n1`
|
cat <<EOF
|
||||||
nojs_file=${nojs_line[(ws: :)1]}
|
|
||||||
nojs_desc=`echo $nojs_line | awk '{ for(c=2;c<=NF;c++) printf("%s ",$c) }'`
|
|
||||||
|
|
||||||
cat <<EOF >> $dst
|
|
||||||
<noscript>
|
<noscript>
|
||||||
<p>You either have JavaScript turned off or your browser doesn't support JavaScript.<br />
|
<p> </p>
|
||||||
This website mostly consists of image galleries and needs JavaScript.</p>
|
<div class="alert">
|
||||||
<!-- just in case there is no javascript, show the first image-->
|
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||||
<img src="${nojs_file}" alt="${nojs_desc}">
|
<strong>Javascript missing</strong>.
|
||||||
|
You either have JavaScript turned off or your browser doesn't support JavaScript.
|
||||||
|
This website mostly consists of image galleries and needs JavaScript.
|
||||||
|
</div>
|
||||||
</noscript>
|
</noscript>
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
# if a file was specified as argument, include it
|
||||||
|
{ test -r "$1" } && { cat "$1" | render_html }
|
||||||
|
|
||||||
# generate the gallery's javascript
|
# generate the gallery's javascript
|
||||||
dst_js="js/${1%.*}-gallery.js"
|
dst_js="js/temp-${RANDOM}-gallery.js"
|
||||||
|
|
||||||
cat <<EOF > pub/${dst_js}
|
cat <<EOF > pub/${dst_js}
|
||||||
var slides= [];
|
var slides= [];
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# parse gallery entries
|
# parse gallery entries
|
||||||
pics=`grep -v '^#' ${src}`
|
pics=`grep -v '^#'`
|
||||||
for p in ${(f)pics}; do
|
for p in ${(f)pics}; do
|
||||||
file=${p[(ws: :)1]}
|
file=${p[(ws: :)1]}
|
||||||
desc=`echo $p | awk '{ for(c=2;c<=NF;c++) printf("%s ",$c) }'`
|
desc=`echo $p | awk '{ for(c=2;c<=NF;c++) printf("%s ",$c) }'`
|
||||||
|
|
@ -260,64 +222,116 @@ blueimp.Gallery(slides, {
|
||||||
fullscreen: true,
|
fullscreen: true,
|
||||||
closeOnEscape: true,
|
closeOnEscape: true,
|
||||||
closeOnSlideClick: true,
|
closeOnSlideClick: true,
|
||||||
closeOnSwipeUpOrDown: false,
|
closeOnSwipeUpOrDown: true,
|
||||||
startSlideshow: true
|
startSlideshow: true,
|
||||||
|
slideshowInterval: 4500,
|
||||||
});
|
});
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# includejs+=(js/blueimp-helper.js)
|
|
||||||
includejs+=(js/jquery.min.js)
|
includejs=(js/jquery.min.js)
|
||||||
includejs+=(js/bootstrap.min.js)
|
includejs+=(js/bootstrap.min.js)
|
||||||
includejs+=(js/blueimp-gallery.min.js)
|
includejs+=(js/blueimp-gallery.min.js)
|
||||||
# includejs+=(js/jquery.blueimp-gallery.min.js)
|
|
||||||
# includejs+=(js/blueimp-gallery-fullscreen.js)
|
|
||||||
includejs+=($dst_js)
|
|
||||||
render_footer >> $dst
|
|
||||||
|
|
||||||
print "done."
|
|
||||||
|
# not really needed
|
||||||
|
# includejs+=(js/blueimp-helper.js)
|
||||||
|
# includejs+=(js/blueimp-gallery-indicator.js)
|
||||||
|
# includejs+=(js/blueimp-gallery-fullscreen.js)
|
||||||
|
# includejs+=(js/jquery.blueimp-gallery.min.js)
|
||||||
|
|
||||||
|
includejs+=($dst_js)
|
||||||
|
|
||||||
|
render_footer
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
read_meta() {
|
read_meta() {
|
||||||
tmp=`awk '
|
tmp=`head -n 3 | awk '
|
||||||
!/^#/ { next }
|
!/^#/ { next }
|
||||||
/title/ { printf "title=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
|
/title/ { printf "title=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
|
||||||
/description/ { printf "description=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
|
/description/ { printf "description=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
|
||||||
/keywords/ { printf "keywords=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
|
/keywords/ { printf "keywords=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
|
||||||
/gallery/ { printf "gallery=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
|
'`
|
||||||
' ${1}`
|
|
||||||
eval "$tmp"
|
eval "$tmp"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
{ test "$1" = "source" } && { return 0 }
|
||||||
|
|
||||||
|
|
||||||
# Main
|
# Main
|
||||||
|
|
||||||
|
mkdir -p pub
|
||||||
|
cat << EOF > pub/.htaccess
|
||||||
|
DirectoryIndex index index.html index.php
|
||||||
|
DefaultType text/html
|
||||||
|
EOF
|
||||||
|
|
||||||
|
act -n "Clean up all temp files ... "
|
||||||
|
temps=(`find pub -type f -name 'temp-*'`)
|
||||||
|
for t in $temps; do rm -f $t; done
|
||||||
|
print "done"
|
||||||
|
|
||||||
|
|
||||||
# render all HTML views
|
# render all HTML views
|
||||||
htmls=(`find views -type f -name '*.html'`)
|
htmls=(`find views -type f -name '*.html'`)
|
||||||
for h in $htmls; do
|
for src in $htmls; do
|
||||||
read_meta ${h}
|
|
||||||
render_html `basename ${h%.*}`
|
# read meta commands
|
||||||
done
|
cat ${src} | read_meta
|
||||||
|
|
||||||
|
# compute destination file
|
||||||
|
dst="pub/`basename ${src%.*}`"
|
||||||
|
|
||||||
|
render_header > $dst
|
||||||
|
cat <<EOF >> $dst
|
||||||
|
<p> </p>
|
||||||
|
<article>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# render html
|
||||||
|
act -n "Html rendering: $dst "
|
||||||
|
cat $src | render_html >> $dst
|
||||||
|
|
||||||
|
cat <<EOF >> $dst
|
||||||
|
</article>
|
||||||
|
<p> </p>
|
||||||
|
EOF
|
||||||
|
|
||||||
|
includejs=(js/bootstrap.min.js)
|
||||||
|
render_footer >> $dst
|
||||||
|
|
||||||
|
act "done"
|
||||||
|
|
||||||
# render all markdown views
|
|
||||||
mds=(`find views -type f -name '*.md'`)
|
|
||||||
for m in $mds; do
|
|
||||||
read_meta ${m}
|
|
||||||
render_markdown `basename ${m%.*}`
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# render all image galleries
|
# render all image galleries
|
||||||
gals=(`find views -type f -name '*.gal'`)
|
gals=(`find views -type f -name '*.gal'`)
|
||||||
for g in $gals; do
|
for src in $gals; do
|
||||||
read_meta ${g}
|
cat ${src} | read_meta
|
||||||
render_gallery `basename ${g%.*}`
|
dst="pub/`basename ${src%.*}`"
|
||||||
|
act -n "Gallery rendering: $dst ... "
|
||||||
|
cat $src | render_gallery > $dst
|
||||||
|
print "done"
|
||||||
done
|
done
|
||||||
|
|
||||||
for m in `find views -mindepth 1 -type d `; do
|
for m in `find views -mindepth 1 -type d `; do
|
||||||
act -n "publishing $m... "
|
act -n "publishing $m... "
|
||||||
rsync -r $m pub/
|
rsync -r $m pub/
|
||||||
print done
|
print "done"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# if the whole website is a "slideshow" typology then we start with
|
||||||
|
# a full screen slideshow of all uploaded photos, cycling random every time.
|
||||||
|
# galleries are supported and can be linked in menu and pages.
|
||||||
|
{ test "$WEBSITE" = "slideshow" } && {
|
||||||
|
notice "Site is configured as slideshow"
|
||||||
|
# generate a list of all images (removing duplicates)
|
||||||
|
act "Indexing all images ... "
|
||||||
|
find pub -iname '*.jpg' | sed -e 's/^pub\///g' -e 's/^.\/pub\///g' -e "s@'@@g" | sort | uniq \
|
||||||
|
| render_gallery views/index.html > pub/index
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
act "Website refreshed."
|
act "Website refreshed."
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,10 @@
|
||||||
<div class="navbar-inner">
|
<div class="navbar-inner">
|
||||||
|
|
||||||
<a href="index">
|
<a href="index">
|
||||||
|
<div class="brand">
|
||||||
|
|
||||||
<!-- customise this with your icon and brand -->
|
<!-- customise this with your icon and brand -->
|
||||||
<i class="icon-home></i> Welcome
|
<i class="icon-home"></i> Welcome
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|
@ -30,5 +31,4 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
|
|
|
||||||
6
update
6
update
|
|
@ -29,7 +29,7 @@ source utils
|
||||||
bootstrap2="http://twitter.github.io/bootstrap/assets/bootstrap.zip"
|
bootstrap2="http://twitter.github.io/bootstrap/assets/bootstrap.zip"
|
||||||
blueimp_gallery="https://github.com/blueimp/Gallery.git"
|
blueimp_gallery="https://github.com/blueimp/Gallery.git"
|
||||||
|
|
||||||
|
{ test "$1" = "" } || { test "$1" = "bootstrap" } && {
|
||||||
notice "Downloading and installing the latest Bootstrap2"
|
notice "Downloading and installing the latest Bootstrap2"
|
||||||
act "url: $bootstrap2"
|
act "url: $bootstrap2"
|
||||||
curl "$bootstrap2" -o bootstrap.zip
|
curl "$bootstrap2" -o bootstrap.zip
|
||||||
|
|
@ -39,7 +39,9 @@ rsync -r bootstrap/js .
|
||||||
rsync -r bootstrap/img .
|
rsync -r bootstrap/img .
|
||||||
rm -rf bootstrap bootstrap.zip
|
rm -rf bootstrap bootstrap.zip
|
||||||
act "Bootstrap2 installed"
|
act "Bootstrap2 installed"
|
||||||
|
}
|
||||||
|
|
||||||
|
{ test "$1" = "" } || { test "$1" = "blueimp" } && {
|
||||||
notice "Downloading and installing BlueImp gallery"
|
notice "Downloading and installing BlueImp gallery"
|
||||||
git clone ${blueimp_gallery} blueimp
|
git clone ${blueimp_gallery} blueimp
|
||||||
rsync -r blueimp/css .
|
rsync -r blueimp/css .
|
||||||
|
|
@ -47,4 +49,6 @@ rsync -r blueimp/js .
|
||||||
rsync -r blueimp/img .
|
rsync -r blueimp/img .
|
||||||
rm -rf blueimp
|
rm -rf blueimp
|
||||||
act "BlueImp installed"
|
act "BlueImp installed"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue