#!/usr/bin/env dash # author: nunavut # version: 1.2 # this script generates simple pages with markdown. requires lowdown #< variables > readonly VERSION='1.2' #< functions > #<--- simple functions ---> msg() { printf "%s$@\n";} #<-- ... die() { printf "%s$@\n";exit 1;} #<-- ... _param_parse() { grep -Ei "^$1: " "$2"|cut -d' ' -f2-|head -n1;} #_random() { hexdump /dev/random|head -n2|cut -d' ' -f2-|tr -d ' '|tr -d '\n';} #<-- generate a random string _configs() { nick='Nunavut' license="'Intellectual Property' doesn't exist." date=$(LANG='en_US.UTF-8' date "+%A, %d/%m/%Y %H:%M:%S");} _usage() { printf "usage: $0 [build] [help] build: generate\nhelp: print help\n" } _check_files() { find ./*.md > /dev/null 2>&1 || die "error: no markdown files. $0 cannot build without it." } _check_index() { [ -f ../index.html ] && printf "%s\n" || false } _check_homepage() { if [ -f ./index.html ]; then [ ! "$markdown" = 'index.md' ] && printf "%s\n" || false fi } _check_author() { [ -n "$author" ] && printf "%s

This page was made by $author.

\n" || false } _check_last_edited_by() { [ -n "$last_edited_by" ] && printf "%s

Last edited by $last_edited_by.

\n" || false } _generate_navbar() { [ -f nav.csv ] || return printf "" } #<--- generation ---> _generate() { _configs for markdown in *.md; do author=$(_param_parse author "$markdown") last_edited_by=$(_param_parse 'last-edited-by' "$markdown") title=$(_param_parse name "$markdown") html=$(echo "$markdown"|sed 's/\.md$/\.html/g') cat < $html $title

$title

$(_generate_navbar)
$(lowdown "$markdown") $(_check_index)$(_check_homepage)$(_check_author)$(_check_last_edited_by)
EOFHTML done } #< options > case "$1" in build) _check_files && msg "generating...\n" && _generate && msg "ok!" || msg "unknown error.";; help|*) _usage;; esac