mars

superminimal static website framework
git clone git://parazyd.org/mars.git
Log | Files | Refs | README | LICENSE

commit 364b7c8472a33a596b6cabfb3c01e9c5b7ea7821
parent 833a986f31fe7408d6b68bc4a05ac3b551dde87c
Author: parazyd <parazyd@dyne.org>
Date:   Fri,  1 Jul 2016 15:01:24 +0200

add more markdown and bloat

Diffstat:
Mmars.sh | 124++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Mwebtree | 28++++++++++++++++++++++------
2 files changed, 88 insertions(+), 64 deletions(-)

diff --git a/mars.sh b/mars.sh @@ -3,7 +3,9 @@ # Copyright (c) 2015-2016 parazyd # mars is written and maintained by parazyd <parazyd@dyne.org> # -# This file is part of mars +# ┏┳┓┏━┓┏━┓┏━┓ +# This file is part of ┃┃┃┣━┫┣┳┛┗━┓ +# ╹ ╹╹ ╹╹┗╸┗━┛ # # This source code is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,94 +20,100 @@ # You should have received a copy of the GNU General Public License # along with this source code. If not, see <http://www.gnu.org/licenses/>. autoload colors; colors +setopt pushdsilent source webtree +# {{{ helpers +err() { msgstr="$*" && print "${fg[red]}(*) error: $msgstr ${reset_color}"; return 1 } +inf() { msgstr="$*" && print "${fg[green]}(*) $msgstr ${reset_color}" } +wrn() { msgstr="$*" && print "${fg[yellow]}(*) warning: $msgstr ${reset_color}" } +msgokay() { printf "[ ${fg[green]}OK${reset_color} ]" } +msgnope() { printf "[${fg[red]}NOPE${reset_color}]" } +msgskip() { printf "[${fg[yellow]}SKIP${reset_color}]" } + +countdown() { + watdo="$*" + printf "\n===========================================================\n" + printf " ${fg[white]} > ${reset_color} $watdo in: ${fg[red]} 5 4 3 2 1... ${reset_color}(hit ^C to abort)" && sleep 1 && \ + printf " ${fg[white]} >> ${reset_color} $watdo in: ${fg[red]} 4 3 2 1... ${reset_color}(hit ^C to abort)" && sleep 1 && \ + printf " ${fg[white]} >>>${reset_color} $watdo in: ${fg[red]} 3 2 1.. ${reset_color}(hit ^C to abort)" && sleep 1 && \ + printf " ${fg[white]} >> ${reset_color} $watdo in: ${fg[red]} 2 1.. ${reset_color}(hit ^C to abort)" && sleep 1 && \ + printf " ${fg[white]} > ${reset_color} $watdo in: ${fg[red]} 1. ${reset_color}(hit ^C to abort)" && sleep 1 && \ + printf " ${fg[green]} >>>${reset_color} $watdo " + printf "\n===========================================================\n\n" +} + +trapctrlc() { print "\n\n"; wrn "aborting..."; exit 2 } +trap "trapctrlc" 2 +# }}} generate() { - print "${fg[green]}(*) generating your static pages${reset_color}" + inf "generating your static html" for dir in $tree; do - pushd $dir - pages=($(ls *.$pageformat)) print "${fg[blue]} -- /$dir --${reset_color}" + pushd $dir && pages=(`ls *.$pageformat`) && { + for page in $pages; do + [[ -n "${exclude[(r)$page]}" ]] && { skip-page; continue } || process-page + done && popd && continue + } || { wrn "directory unusable" && popd } + done +} - for page in $pages; do - [[ -n "${exclude[(r)$page]}" ]] && { skip-page; continue } || process-page - done && popd +clean() { + countdown "cleaning" && \ + for dir in $tree; do + print "${fg[blue]} -- /$dir --${reset_color}" + pushd $dir && pages=($(ls *.$pageformat)) && { + for page in $pages; do + [[ -n "${exclude[(r)$page]}" ]] || name=${page[(ws:.:)1]} + printf "${fg[blue]}(*) ${reset_color}" && rm -v $name.html + done && popd + } || { wrn "directory unusable" && popd } done } + process-page() { name=${page[(ws:.:)1]} - case $pageformat in php) php -f $page > $name.html \ - && print "[ ${fg[green]}OK${reset_color} ] $name.$pageformat -> $name.html" \ - || print "[${fg[red]}NOPE${reset_color}] $name.$pageformat -> $name.html" - ;; + && print "$(msgokay) $name.$pageformat -> $name.html" \ + || print "$(msgnope) $name.$pageformat -> $name.html";; - md) - # here we try to check for includes (lazy) - local includes=`awk '/^##+/ {print $2}'` - [[ -n $includes ]] && { - for file in $includes; do - python -m markdown $file > $name.html - done - } + md|markdown) + [[ -z $precontent ]] || { + for i in $precontent; do + cat $i >> $name.html + done } python -m markdown $page >> $name.html \ - && print "[ ${fg[green]}OK${reset_color} ] $name.$pageformat -> $name.html" \ - || print "[${fg[red]}NOPE${reset_color}] $name.$pageformat -> $name.html" - ;; + && print "$(msgokay) $name.$pageformat -> $name.html" \ + || print "$(msgnope) $name.$pageformat -> $name.html" + + [[ -z $postcontent ]] || { + for i in $postcontent; do + cat $i >> $name.html + done } ;; + *) - print "${fg[red]}(*) error: $pageformat page format is not supported${reset_color}";; + err "$pageformat is unsupported";; esac } skip-page() { - name=${page[(ws:.:)1]} - print "[${fg[yellow]}SKIP${reset_color}] $name.$pageformat -> $name.html" -} - -clean() { - print "${fg[green]}(*) cleaning...${reset_color}" - for dir in $tree; do - pushd $dir - pages=($(ls *.$pageformat)) - print "${fg[blue]} -- /$dir --${reset_color}" - - for page in $pages; do - [[ -n "${exclude[(r)$page]}" ]] || { - name=${page[(ws:.:)1]} - printf "${fg[blue]}(*) ${reset_color}" && rm -v $name.html - } - done && popd - done + [[ -z $VERBOSE ]] || { + name=${page[(ws:.:)1]} && print "$(msgskip) $name.$pageformat -> $name.html" } + return 0 } push() { - countdown rsyncing + countdown "rsyncing" && \ rsync -P -e 'ssh' -avul --delete --stats \ --size-only \ --exclude-from 'rsync-exclude' \ . $WEBHOST:$WEBROOT } -countdown() { - watdo="$*" - printf " ${fg[white]}>>>${reset_color} $watdo in: ${fg[red]} 5 4 3 2 1... ${reset_color}(hit ^C to abort)" && sleep 1 && \ - printf " ${fg[white]}>>>${reset_color} $watdo in: ${fg[red]} 4 3 2 1... ${reset_color}(hit ^C to abort)" && sleep 1 && \ - printf " ${fg[white]}>>>${reset_color} $watdo in: ${fg[red]} 3 2 1... ${reset_color}(hit ^C to abort)" && sleep 1 && \ - printf " ${fg[white]}>>>${reset_color} $watdo in: ${fg[red]} 2 1... ${reset_color}(hit ^C to abort)" && sleep 1 && \ - printf " ${fg[white]}>>>${reset_color} $watdo in: ${fg[red]} 1... ${reset_color}(hit ^C to abort)" && sleep 1 && \ - printf " ${fg[white]}>>>${reset_color} $watdo in: ${fg[red]} ${reset_color}(hit ^C to abort)\n" -} - -trapctrlc() { - echo "\n\n${fg[yellow]}(*) aborting...${reset_color}" - exit 2 -} - -trap "trapctrlc" 2 case "$1" in generate) generate;; clean) clean;; diff --git a/webtree b/webtree @@ -1,12 +1,12 @@ -# Here configure your webserver and webroot path for rsync +# here configure your webserver and webroot path for rsync WEBHOST="foo.bar.org" WEBROOT="/var/www/public_html/" -# Set the format of your pages (php or markdown) -pageformat=php -#pageformat=md +# set the format of your pages (php or markdown) +#pageformat=php +pageformat=md -# Here add the tree of your website, ex: +# here add the tree of your website, ex: # # tree=( # . @@ -24,9 +24,25 @@ tree=( example ) -# Here add files you want excluded from being generated as .html +# here add files you want excluded from being generated as .html exclude=( header.php navigation.php footer.php ) + +# exclude=( +# README.md +# INSTALL.md +# ) + +## markdown specific settings +[[ $pageformat == md ]] && { ## markdown specific settings + + # html that is put in order before the conten + precontent=(header.html navigation.html) + + # html that is put in order after the content + postcontent=(footer.html) + +}