summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaromil <jaromil@dyne.org>2012-10-19 12:05:03 (GMT)
committer Jaromil <jaromil@dyne.org>2012-10-19 12:05:03 (GMT)
commit977e36d32db8b01f5b50219b21ab75348050d8b2 (patch)
tree6a3997277c468087b223ded925834e42ea6f2663
initial commit for a standalone script directory
-rwxr-xr-xinit97
-rwxr-xr-xrender260
2 files changed, 357 insertions, 0 deletions
diff --git a/init b/init
new file mode 100755
index 0000000..9da0bbb
--- /dev/null
+++ b/init
@@ -0,0 +1,97 @@
+#!/usr/bin/env zsh
+#
+# Jaro Web, your slick and static website publisher
+#
+# Copyleft (C) 2012 Denis Roio <jaromil@dyne.org>
+#
+# 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.
+
+mkdir views
+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>
+
+EOF
+mkdir tmpl
+car <<EOF > tmpl/header
+EOF
+cat <<EOF > tmpl/footer.html
+<hr>
+<footer style="padding: 1em;">
+ <div class="pull-left">
+ <small>All information found on this page is free to copy</small>
+ </div>
+
+ <small class="pull-right">Website made in HTML5<br />using <a
+ href="http://jaroweb.dyne.org" target="_blank">Jaro
+ Web</a></small>
+
+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
+
+</footer>
+</div><!--/.container-->
+
+<script src="js/bootstrap.js"></script>
+
+ </body>
+</html>
+
+EOF
+cat <<EOF > tmpl/header.html
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+<meta name="Generator" content="Jaro Web http://jaroweb.dyne.org" />
+<meta name="MSSmartTagsPreventParsing" content="True" />
+
+<!-- Bootstrap -->
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<link href="css/bootstrap.min.css" rel="stylesheet">
+<link href="css/bootstrap-responsive.css" rel="stylesheet">
+
+<link rel="shortcut icon" href="/favicon.ico">
+
+<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
+<!--[if lt IE 9]>
+ <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
+ <![endif]-->
+
+</head>
+<body>
+ <div class="container">
+EOF
+notice "Downloading and installing Bootstrap"
+curl http://twitter.github.com/bootstrap/assets/bootstrap.zip -o bootstrap.zip
+unzip bootstrap.zip
+mv bootstrap/css views/
+mv bootstrap/js views/
+mv bootstrap/img views/
+rm -rf bootstrap bootstrap.zip
+act "Bootstrap installed"
+
+cat <<EOF > Makefile
+all:
+ @./jaroweb/render
+
+clean:
+ rm -rf pub
+
+upload:
+ @scp -r pub/.htaccess pub/* online.server.org:/var/www
diff --git a/render b/render
new file mode 100755
index 0000000..a9be1d9
--- /dev/null
+++ b/render
@@ -0,0 +1,260 @@
+#!/usr/bin/env zsh
+#
+# Jaro Web, your slick and static website publisher
+#
+# Copyleft (C) 2012 Denis Roio <jaromil@dyne.org>
+#
+# 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.
+
+# standard output message routines
+# it's always useful to wrap them, in case we change behaviour later
+notice() { if [[ $QUIET == 0 ]]; then print "$fg_bold[green][*]$fg_no_bold[default] $1" >&2; fi }
+error() { if [[ $QUIET == 0 ]]; then print "$fg[red][!]$fg[default] $1" >&2; fi }
+func() { if [[ $DEBUG == 1 ]]; then print "$fg[blue][D]$fg[default] $1" >&2; fi }
+act() {
+ if [[ $QUIET == 0 ]]; then
+ if [ "$1" = "-n" ]; then
+ print -n "$fg_bold[white] . $fg_no_bold[default] $2" >&2;
+ else
+ print "$fg_bold[white] . $fg_no_bold[default] $1" >&2;
+ fi
+ fi
+}
+
+# honor quiet and debug flags as early as possible
+if [[ ${@} == *-q* ]]; then QUIET=1; fi
+if [[ ${@} == *-D* ]]; then DEBUG=1; fi
+
+# what operating system are we in? use os_detect()
+# simplifying modes of operation: GNU or MAC
+case $(uname) in
+ Linux) OS=GNU
+ notice "Jaro Mail v$VERSION running on GNU/Linux" ;;
+
+ Darwin) OS=MAC
+ notice "Jaro Mail v$VERSION running on Mac/OSX" ;;
+
+ *) OS=GNU # default
+ error "Running on an unknown operating system, assuming GNU" ;;
+esac
+
+{ 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"
+
+mkdir -p pub
+cat << EOF > pub/.htaccess
+DirectoryIndex index index.html index.php
+DefaultType text/html
+EOF
+
+
+render_html() {
+
+ src=`find views -type f -name "${1}.html"`
+ { test -r "${src}" } || {
+ print "${1} html not found";
+ return 1 }
+
+
+ dst="pub/${1}"
+
+ print -n "rendering $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
+
+ cat <<EOF > $dst
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>$TITLE</title>
+ <meta name="description" content="$DESCRIPTION">
+ <meta name="keywords" content="$KEYWORDS">
+EOF
+ cat tmpl/header.html >> $dst
+ echo "<nav>" >> $dst
+ render_navbar ${sec} >> $dst
+ echo "</nav>" >> $dst
+
+ echo "<article>" >> $dst
+ grep -v '^#' ${src} >> $dst
+ echo "</article>" >> $dst
+
+ cat tmpl/footer.html >> $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 "\";" }
+ /link/ { printf "link=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
+ /image/ { printf "image=\""; for(i=3;i<=NF;i++) printf "%s ", $i; printf "\";" }
+ ' ${1}`
+ eval "$tmp"
+}
+
+render_section() {
+ sname=${1}
+ spath=views/${sname}
+
+
+ { test -d ${spath} } && {
+ # the section is a directory containing files
+ # so we generate its html
+
+ pages=`find ${spath} -type f`
+ { test ${#pages} = 0 } && {
+ print "${sname} section is an empty directory"
+ return 1 }
+
+ print "${sname} section"
+ print "<h1>${sname//_/ }</h1>" > ${spath}.html
+
+ for p in ${(f)pages}; do
+ pp=`basename $p`
+ case ${pp[(ws:.:)2]} in
+
+ html)
+ read_meta $p
+ # fill in entry into section page
+ cat <<EOF >> ${spath}.html
+<h2>$title</h2>
+<p>$description</p>
+EOF
+ # print "Title: $title"
+ # print "Description: $description"
+ # print "Keywords: $keywords"
+ render_html ${pp[(ws:.:)1]}
+ ;;
+
+ link)
+ print -n "rendering $pp... "
+ read_meta $p
+ cat <<EOF >> ${spath}.html
+<h2><a href="$link" target="_blank">$title</a></h2>
+<p>$description</p>
+EOF
+ print "done."
+ ;;
+ *)
+ print "${p}: page type unknown"
+ ;;
+
+ esac
+
+ done # pages
+
+ }
+
+ { test -r ${spath}.html } || {
+ print "${sname} section not found in views"
+ return 1 }
+
+ # render section's overview
+ render_html ${sname}
+ # at this point the section is an actual html file
+
+}
+
+render_navbar() {
+ active=${1}
+
+ cat <<EOF
+<!-- BEGIN NAVIGATION BAR -->
+ <div class="navbar navbar-fixed-top">
+ <div class="navbar-inner">
+ <div class="brand">&nbsp;&nbsp;&nbsp;${BRAND}</div>
+ <ul class="nav">
+ <li class="divider-vertical"></li>
+EOF
+
+# first section: overview
+ if [ "$active" = "views" ]; then
+ cat <<EOF
+<li class="active"><a href="index">intro</a></li>
+EOF
+ else
+ cat <<EOF
+<li><a href="index">intro</a></li>
+EOF
+ fi
+
+# other sections
+ for sec in ${sections}; do
+ ssec=`basename $sec`
+ if [ "$ssec" = "$active" ]; then
+ cat <<EOF
+ <li class="active"><a href="${ssec}">${ssec//_/ }</a></li>
+EOF
+ else
+ cat <<EOF
+ <li><a href="${ssec}">${ssec//_/ }</a></li>
+EOF
+ fi
+ done
+
+ # complete navbar with static entries if present
+ { test -r tmpl/navbar.html } && { cat tmpl/navbar.html }
+
+ cat <<EOF
+ </ul>
+ </div>
+ </div>
+<!-- END NAVIGATION BAR -->
+EOF
+}
+
+
+# Main
+
+render_html index
+
+act "${#sections} sections configured"
+
+if [ ${#sections} = 0 ]; then
+ act "No sections configured"
+else
+
+ for s in ${sections}; do
+
+ render_section ${s}
+
+ done
+
+fi
+
+for m in `find views -mindepth 1 -type d `; do
+ rsync -r $m pub/
+ notice "$m published"
+done
+act "Website refreshed."