#!/usr/bin/env zsh # # Jaro Web, your slick and static website publisher # # Copyleft (C) 2012-2013 Denis Roio # # This source code is free software; you can redistribute it and/or # modify it under the terms of the GNU Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This source code is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # Please refer to the GNU Public License for more details. # # You should have received a copy of the GNU Public License along with # this source code; if not, write to: # Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. source jaroweb/utils { test -r config.zsh } || { error "Directory not configured for Jaro Web. First use jaroweb init" exit 1 } #################################### source config.zsh notice "Rendering $BRAND website" 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 < $TITLE EOF { test "$1" = "" } || { echo "${@}"; echo } cat tmpl/header.html cat <
EOF cat tmpl/navbar.html } render_footer() { cat tmpl/footer.html cat < EOF { test "$1" = "" } || { echo "${@}"; echo } for i in $includejs; do echo "" done cat < EOF } render_html() { src=`find views -type f -name "${1}.html"` { test -r "${src}" } || { print "${1} section not found"; return 1 } dst="pub/${1}" act -n "rendering html: $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 "
" >> $dst grep -v '^#' ${src} >> $dst echo "
" >> $dst 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 "
" >> $dst cat ${src} | markdown >> $dst echo "
" >> $dst includejs+=(js/bootstrap.min.js) render_footer >> $dst print "done." } render_gallery() { src=`find views -type f -name "${1}.gal"` { test -r "${src}" } || { print "${1} section not found"; return 1 } dst="pub/${1%.*}" act -n "rendering gallery: $dst... " render_header "" > $dst cat <> $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 <> $dst EOF # generate the gallery's javascript dst_js="js/${1%.*}-gallery.js" cat < pub/${dst_js} var slides= []; EOF # parse gallery entries pics=`grep -v '^#' ${src}` for p in ${(f)pics}; do file=${p[(ws: :)1]} desc=`echo $p | awk '{ for(c=2;c<=NF;c++) printf("%s ",$c) }'` cat << EOF >> pub/$dst_js slides.push({ href: '${file}', title: '${desc}' }); EOF done cat <> pub/$dst_js function shuffle(array) { var m = array.length, t, i; // While there remain elements to shuffle… while (m) { // Pick a remaining element… i = Math.floor(Math.random() * m--); // And swap it with the current element. t = array[m]; array[m] = array[i]; array[i] = t; } return array; } slides = shuffle(slides); blueimp.Gallery(slides, { container: '#blueimp-gallery', carousel: true, fullscreen: true, closeOnEscape: true, closeOnSlideClick: true, closeOnSwipeUpOrDown: false, startSlideshow: true }); 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." } read_meta() { tmp=`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" } # Main # render all HTML views htmls=(`find views -type f -name '*.html'`) for h in $htmls; do read_meta ${h} render_html `basename ${h%.*}` 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%.*}` done for m in `find views -mindepth 1 -type d `; do act -n "publishing $m... " rsync -r $m pub/ print done done act "Website refreshed."