#!/bin/bash #shellcheck disable=SC1090 . "$(sfpath)" || exit 3 shellfu import pretty usage() { mkusage "$@" \ "[options] SRC DST" \ -- \ "Copy tree from SRC to DST, converting Markdown to HTML pages." \ "" \ -o \ "-d, --debug Turn on debbugging output" \ "--log LOG Store publish plan in LOG file. (Keep this" \ " file PRIVATE!)" \ "--if-ready Publish only if .mdpublish/ready file exists;" \ " delete it afterwards (useful for cron jobs)" \ "-f, --force Remove all content from DST beforehand" \ "-v, --verbose Be more verbose" \ "--version Show version" \ -- \ "By default, mdpublish does not keep logfile. If you provide" \ "one, make sure it's outside the published content, otherwise" \ "someone might get list of all files on your site." } # # Markdown to HTML command # # Has to accept Markdown on standard input and pring HTML on standard # output. # MDPUBLISH__MDBIN=${MDPUBLISH__MDBIN:-markdown} # # Logfile for plan details # MDPUBLISH__LOG=${MDPUBLISH__LOG:-/dev/null} # # Style to load into each generated HTML page # MDPUBLISH__STYLE="_mdpublish/style.css" # # Nav to load for each generated HTML page # MDPUBLISH__NAV=".mdpublish/nav" nonempty() { # # True if directory $1 has files # local dir=$1 local es test -n "$dir" \ || warn "usage: nonempty DIR" test -d "$dir" \ || warn "usage: nonempty DIR" test -e "$dir"/* 2>/dev/null; es=$? case $es in 0) return 0 ;; # one file 2) return 0 ;; # more files (`test` usage error) *) return 1 ;; # anything else esac } mktitle() { # # Read title from Markdown file $MdSrc # local lines=() local head head="$(head -3 "$MdSrc")" readarray lines <<<"$head" debug -v head lines test -n "${lines[0]}" || return 1 grep -qx '==*' <<<"${lines[1]}" || return 1 test -n "${lines[2]}" && return 1 echo "${lines[0]}" return 0 } mkhead() { # # Print page head # echo '' echo '' echo '
' echo "