mars

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

commit 91952782f79c74d2574579c0209de5af911923c4
parent fa85648b61b1fcbca9834482f42e4576f4b5e5fa
Author: parazyd <parazyd@dyne.org>
Date:   Wed,  7 Sep 2016 22:39:43 +0200

rename mars.sh to mars; don't use `ls` anymore

Diffstat:
Amars | 144+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dmars.sh | 141-------------------------------------------------------------------------------
2 files changed, 144 insertions(+), 141 deletions(-)

diff --git a/mars b/mars @@ -0,0 +1,144 @@ +#!/usr/bin/env zsh +# +# Copyright (c) 2015-2016 parazyd +# mars is written and maintained by parazyd <parazyd@dyne.org> +# +# ┏┳┓┏━┓┏━┓┏━┓ +# 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 +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This software 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. See the +# GNU General Public License for more details. +# +# 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() { + rm -f $tmpage + print "\n\n"; wrn "aborting..."; exit 2 +} +trap "trapctrlc" 2 +# }}} + +generate() { + inf "generating your static html" + for dir in $tree; do + print "${fg[blue]} -- /$dir --${reset_color}" + pushd $dir && { + for page in *.$pageformat; do + [[ -e "$page" ]] || continue + [[ -n "${exclude[(r)$page]}" ]] && { skip-page; continue } || process-page + done && popd && continue + } || { wrn "directory unusable" && popd } + done +} + +clean() { + [[ "$1" == "-f" ]] || { countdown "cleaning" } + for dir in $tree; do + print "${fg[blue]} -- /$dir --${reset_color}" + pushd $dir && { + for page in *.$pageformat; do + [[ -e "$page" ]] || continue + [[ -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 "$(msgokay) $name.$pageformat -> $name.html" \ + || print "$(msgnope) $name.$pageformat -> $name.html";; + + md|markdown) + rm -f $name.html + [[ -z $precontent ]] || { + for i in $precontent; do + cat $i >> $name.html + done } + + local pagetitle=`grep '^##+TITLE ' $page | cut -c 10- -` + sed -i -e 's/<title>.*<\/title>/<title>'$pagetitle'<\/title>/' $name.html + tmpage=`mktemp` && cp $page $tmpage + sed -i -e 's/##+TITLE .*//' $tmpage + + python -m markdown $tmpage >> $name.html \ + && print "$(msgokay) $name.$pageformat -> $name.html" \ + || print "$(msgnope) $name.$pageformat -> $name.html" + + rm $tmpage + + [[ -z $postcontent ]] || { + for i in $postcontent; do + cat $i >> $name.html + done } + + [[ `grep $name.html $name.html` ]] && { + sed -i -e 's/class="thisPage" //' $name.html + sed -i -e 's/href="\/'$name'.html"/class="thisPage" href="\/'$name'.html"/' $name.html + } || { + local dirstr=`basename $PWD` + [[ `grep '"/'$dirstr'/"' $name.html` ]] && { + sed -i -e 's/class="thisPage" //' $name.html + sed -i -e 's/href="\/'$dirstr'\/"/class="thisPage" href="\/'$dirstr'\/"/' $name.html + } || return 0 } ;; + *) + err "$pageformat is unsupported";; + esac +} + +skip-page() { + [[ -z $VERBOSE ]] || { + name=${page[(ws:.:)1]} && print "$(msgskip) $name.$pageformat -> $name.html" } + return 0 +} + +push() { + countdown "rsyncing" && \ + rsync -P -e 'ssh' -avul --delete --stats \ + --size-only \ + --exclude-from 'rsync-exclude' \ + . $WEBHOST:$WEBROOT +} + +case "$1" in + generate) generate;; + clean) clean "$2";; + push) push;; + *) print "usage: `basename $0` {generate|clean|push}";; +esac diff --git a/mars.sh b/mars.sh @@ -1,141 +0,0 @@ -#!/usr/bin/env zsh -# -# Copyright (c) 2015-2016 parazyd -# mars is written and maintained by parazyd <parazyd@dyne.org> -# -# ┏┳┓┏━┓┏━┓┏━┓ -# 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 -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This software 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. See the -# GNU General Public License for more details. -# -# 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() { - rm -f $tmpage - print "\n\n"; wrn "aborting..."; exit 2 -} -trap "trapctrlc" 2 -# }}} - -generate() { - inf "generating your static html" - 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]}" ]] && { skip-page; continue } || process-page - done && popd && continue - } || { wrn "directory unusable" && popd } - done -} - -clean() { - [[ "$1" == "-f" ]] || { 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 "$(msgokay) $name.$pageformat -> $name.html" \ - || print "$(msgnope) $name.$pageformat -> $name.html";; - - md|markdown) - rm -f $name.html - [[ -z $precontent ]] || { - for i in $precontent; do - cat $i >> $name.html - done } - - local pagetitle=`grep '^##+TITLE ' $page | cut -c 10- -` - sed -i -e 's/<title>.*<\/title>/<title>'$pagetitle'<\/title>/' $name.html - tmpage=`mktemp` && cp $page $tmpage - sed -i -e 's/##+TITLE .*//' $tmpage - - python -m markdown $tmpage >> $name.html \ - && print "$(msgokay) $name.$pageformat -> $name.html" \ - || print "$(msgnope) $name.$pageformat -> $name.html" - - rm $tmpage - - [[ -z $postcontent ]] || { - for i in $postcontent; do - cat $i >> $name.html - done } - - [[ `grep $name.html $name.html` ]] && { - sed -i -e 's/class="thisPage" //' $name.html - sed -i -e 's/href="\/'$name'.html"/class="thisPage" href="\/'$name'.html"/' $name.html - } || { - local dirstr=`basename $PWD` - [[ `grep '"/'$dirstr'/"' $name.html` ]] && { - sed -i -e 's/class="thisPage" //' $name.html - sed -i -e 's/href="\/'$dirstr'\/"/class="thisPage" href="\/'$dirstr'\/"/' $name.html - } || return 0 } ;; - *) - err "$pageformat is unsupported";; - esac -} - -skip-page() { - [[ -z $VERBOSE ]] || { - name=${page[(ws:.:)1]} && print "$(msgskip) $name.$pageformat -> $name.html" } - return 0 -} - -push() { - countdown "rsyncing" && \ - rsync -P -e 'ssh' -avul --delete --stats \ - --size-only \ - --exclude-from 'rsync-exclude' \ - . $WEBHOST:$WEBROOT -} - -case "$1" in - generate) generate;; - clean) clean "$2";; - push) push;; - *) print "usage: `basename $0` {generate|clean|push}";; -esac