inline <markdown> rendering

semplified views input with possibility to embed markdown syntax

various improvements and cleanups
This commit is contained in:
Jaromil 2013-08-08 16:36:49 +02:00
parent 32d39df6d0
commit 0647a0fac8
4 changed files with 180 additions and 171 deletions

27
init
View File

@ -51,25 +51,16 @@ mkdir -p tmpl
cp -v jaroweb/js/html5.js views/js }
{ test -r views/css/bootstrap.css } || {
notice "Downloading and installing Bootstrap"
curl http://twitter.github.io/bootstrap/assets/bootstrap.zip -o bootstrap.zip
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"
}
cp -v jaroweb/js/bootstrap* views/js
cp -v jaroweb/css/bootstrap* views/css }
{ test -r views/css/blueimp-gallery.js } || {
notice "Downloading and installing BlueImp gallery"
git clone https://github.com/blueimp/Gallery.git blueimp
rsync -r blueimp/css views/
rsync -r blueimp/js views/
rsync -r blueimp/img views/
rm -rf blueimp
act "BlueImp installed"
}
{ test -r views/css/blueimp-gallery.css } || {
cp -v jaroweb/js/*blueimp* views/js
cp -v jaroweb/css/*blueimp* views/css }
{ test -r views/css/strapdown.css } || {
cp -v jaroweb/js/strapdown.js views/js
cp -v jaroweb/css/strapdown.css views/css }
{ test -r config.zsh } || {
cat <<EOF > config.zsh

258
render
View File

@ -34,11 +34,6 @@ act "Title: $TITLE"
typeset -a includejs
mkdir -p pub
cat << EOF > pub/.htaccess
DirectoryIndex index index.html index.php
DefaultType text/html
EOF
render_header() {
cat <<EOF
@ -49,7 +44,7 @@ render_header() {
<meta name="description" content="$DESCRIPTION" />
<meta name="keywords" content="$KEYWORDS" />
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Generator" content="Jaro Web http://dyne.org/software/jaroweb" />
<meta name="MSSmartTagsPreventParsing" content="True" />
@ -65,6 +60,12 @@ render_header() {
<link href="css/bootstrap-responsive.min.css" rel="stylesheet" />
EOF
{ test -r views/css/style.css } && {
cat <<EOF
<link href="css/style.css" rel="stylesheet" />
EOF
}
{ test "$1" = "" } || { echo "${@}"; echo }
@ -73,7 +74,7 @@ EOF
cat <<EOF
</head> <!-- end of <head> -->
<body>
<body>
<div class="container">
EOF
@ -102,89 +103,48 @@ EOF
render_html() {
src=`find views -type f -name "${1}.html"`
{ test -r "${src}" } || {
print "${1} section not found";
return 1 }
#######################################
## we support the <markdown> tag inline
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... "
# TODO: check duplicates
mds=(`find . -name 'tmp.md*'`)
act -n "${#mds} markdown fields "
# 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
{ test ${#mds} = 0 } || {
# second pass substituted saved parts with rendered markdown
render_header > $dst
for i in $mds; do
md=`basename $i`
newtemp="tmp.$RANDOM"
cat $tmp | awk '
/^'"$md"'/ { system("cat '"$md"' | markdown"); next }
{ print $0; }' > $newtemp
rm $tmp; tmp=$newtemp
done
}
echo "<article>" >> $dst
grep -v '^#' ${src} >> $dst
echo "</article>" >> $dst
cat $tmp
includejs+=(js/bootstrap.min.js)
render_footer >> $dst
print "done."
}
render_markdown() {
src=`find views -type f -name "${1}.md"`
{ test -r "${src}" } || {
print "${1} section not found";
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."
# clean up from temporary files
rm -f tmp.*
}
render_gallery() {
src=`find views -type f -name "${1}.gal"`
{ test -r "${src}" } || {
print "${1} section not found";
return 1 }
render_header "<link rel=\"stylesheet\" href=\"css/blueimp-gallery.min.css\" />"
dst="pub/${1%.*}"
act -n "rendering gallery: $dst... "
render_header "<link rel=\"stylesheet\" href=\"css/blueimp-gallery.min.css\" />" > $dst
cat <<EOF >> $dst
cat <<EOF
<!-- The Gallery as lightbox dialog, should be a child element of the document body -->
<div id="blueimp-gallery" class="blueimp-gallery">
<div class="slides"></div>
@ -198,29 +158,31 @@ cat <<EOF >> $dst
EOF
# embed the first slide into the page for non-javascript browsers
nojs_line=`grep -v '^#' ${src} | head -n1`
nojs_file=${nojs_line[(ws: :)1]}
nojs_desc=`echo $nojs_line | awk '{ for(c=2;c<=NF;c++) printf("%s ",$c) }'`
cat <<EOF >> $dst
# put a notice for non-javascript browsers
cat <<EOF
<noscript>
<p>You either have JavaScript turned off or your browser doesn't support JavaScript.<br />
This website mostly consists of image galleries and needs JavaScript.</p>
<!-- just in case there is no javascript, show the first image-->
<img src="${nojs_file}" alt="${nojs_desc}">
<p>&nbsp;</p>
<div class="alert">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<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>
EOF
# generate the gallery's javascript
dst_js="js/${1%.*}-gallery.js"
# if a file was specified as argument, include it
{ test -r "$1" } && { cat "$1" | render_html }
cat <<EOF > pub/${dst_js}
# generate the gallery's javascript
dst_js="js/temp-${RANDOM}-gallery.js"
cat <<EOF > pub/${dst_js}
var slides= [];
EOF
# parse gallery entries
pics=`grep -v '^#' ${src}`
pics=`grep -v '^#'`
for p in ${(f)pics}; do
file=${p[(ws: :)1]}
desc=`echo $p | awk '{ for(c=2;c<=NF;c++) printf("%s ",$c) }'`
@ -232,7 +194,7 @@ slides.push({
EOF
done
cat <<EOF >> pub/$dst_js
cat <<EOF >> pub/$dst_js
function shuffle(array) {
var m = array.length, t, i;
@ -255,69 +217,121 @@ function shuffle(array) {
slides = shuffle(slides);
blueimp.Gallery(slides, {
container: '#blueimp-gallery',
carousel: true,
fullscreen: true,
closeOnEscape: true,
closeOnSlideClick: true,
closeOnSwipeUpOrDown: false,
startSlideshow: true
container: '#blueimp-gallery',
carousel: true,
fullscreen: true,
closeOnEscape: true,
closeOnSlideClick: true,
closeOnSwipeUpOrDown: true,
startSlideshow: true,
slideshowInterval: 4500,
});
EOF
# includejs+=(js/blueimp-helper.js)
includejs+=(js/jquery.min.js)
includejs+=(js/bootstrap.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."
includejs=(js/jquery.min.js)
includejs+=(js/bootstrap.min.js)
includejs+=(js/blueimp-gallery.min.js)
# 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() {
tmp=`awk '
tmp=`head -n 3 | awk '
!/^#/ { next }
/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 "\";" }
/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"
}
{ test "$1" = "source" } && { return 0 }
# 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
htmls=(`find views -type f -name '*.html'`)
for h in $htmls; do
read_meta ${h}
render_html `basename ${h%.*}`
done
for src in $htmls; do
# read meta commands
cat ${src} | read_meta
# compute destination file
dst="pub/`basename ${src%.*}`"
render_header > $dst
cat <<EOF >> $dst
<p>&nbsp;</p>
<article>
EOF
# render html
act -n "Html rendering: $dst "
cat $src | render_html >> $dst
cat <<EOF >> $dst
</article>
<p>&nbsp;</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
# render all image galleries
gals=(`find views -type f -name '*.gal'`)
for g in $gals; do
read_meta ${g}
render_gallery `basename ${g%.*}`
for src in $gals; do
cat ${src} | read_meta
dst="pub/`basename ${src%.*}`"
act -n "Gallery rendering: $dst ... "
cat $src | render_gallery > $dst
print "done"
done
for m in `find views -mindepth 1 -type d `; do
act -n "publishing $m... "
rsync -r $m pub/
print done
print "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."

View File

@ -1,34 +1,34 @@
<nav>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<a href="index">
<!-- customise this with your icon and brand -->
<i class="icon-home></i> &nbsp;&nbsp;Welcome
</div>
</a>
<ul class="nav">
<li class="divider-vertical"></li>
<!-- customise below with a list of pages -->
<li><a href="artworks">artworks</a></li>
<li><a href="writings">writings</a></li>
<li><a href="media">media</a></li>
<li class="divider-vertical"></li>
<li><a href="contact">contact</a></li>
</ul>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<a href="index">
<div class="brand">
<!-- customise this with your icon and brand -->
<i class="icon-home"></i> &nbsp;&nbsp;Welcome
</div>
</a>
<ul class="nav">
<li class="divider-vertical"></li>
<!-- customise below with a list of pages -->
<li><a href="artworks">artworks</a></li>
<li><a href="writings">writings</a></li>
<li><a href="media">media</a></li>
<li class="divider-vertical"></li>
<li><a href="contact">contact</a></li>
</ul>
</div>
</div>
</div>
</nav>

6
update
View File

@ -29,7 +29,7 @@ source utils
bootstrap2="http://twitter.github.io/bootstrap/assets/bootstrap.zip"
blueimp_gallery="https://github.com/blueimp/Gallery.git"
{ test "$1" = "" } || { test "$1" = "bootstrap" } && {
notice "Downloading and installing the latest Bootstrap2"
act "url: $bootstrap2"
curl "$bootstrap2" -o bootstrap.zip
@ -39,7 +39,9 @@ rsync -r bootstrap/js .
rsync -r bootstrap/img .
rm -rf bootstrap bootstrap.zip
act "Bootstrap2 installed"
}
{ test "$1" = "" } || { test "$1" = "blueimp" } && {
notice "Downloading and installing BlueImp gallery"
git clone ${blueimp_gallery} blueimp
rsync -r blueimp/css .
@ -47,4 +49,6 @@ rsync -r blueimp/js .
rsync -r blueimp/img .
rm -rf blueimp
act "BlueImp installed"
}