From 454804f334f9b08e6629a3f5dd57eebabc970d52 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 22 Nov 2021 21:05:39 -0600 Subject: [PATCH] No, actually. . . paste lib.sh into bread --- bread/bin/bread | 129 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 127 insertions(+), 2 deletions(-) diff --git a/bread/bin/bread b/bread/bin/bread index 28d9b64..97a4d18 100755 --- a/bread/bin/bread +++ b/bread/bin/bread @@ -5,8 +5,133 @@ : "${BREADNEWS:=/bread/news}" : "${BREADDOCS:=/bread/docs}" -#shellcheck disable=1091 -#. /bread/site/lib.sh +### Here's the bit that /was/ in lib.sh + +#shellcheck disable=2034 +DISCOUNT="markdown -f links,image,pants,html,autolink,fencedcode" + +alias p=echo +alias l='p >&2' +N(){ f="${1:-$F}";n="${f#$UNKI/}";p "${n%.*}";} +NN(){ f="${1:-$F}";n="${f##*/}";p "${n%%.*}";} +N_(){ f="${1:-$F}";n="$(N "$f")";p "${n#_}";} +M(){ sed '/^$/q' "${2:-$F}"|grep "^$1"|cut -f2-;} +C(){ sed '1,/^$/d' "${1:-$F}";} +X(){ + Xd=$((Xd+1)); + eval "$(p "set -e";p "cat<<$UNKZ$Xd";cat "${1:--}"|sed 's/`/\\`/g';p;p "$UNKZ$Xd")"; +} + +modmsg() +{ # message as to when a page was modified + date -d "$1" \ + +'this page was updated on ' +} + +series() +{ + in="$(cat)" + s="$*" + if [ -n "$in" ]; then + s="$s $in" + fi + if [ -z "$s" ]; then + return + fi + tx "part of the $s series" +} + +wrapstr() +{ # wrap a non-empty string + sed -e "s_^._<$*>&_" -e "s_.\$_&_" +} + +addstr() +{ # add a string after, but not after an empty string + sed "s/^.\+\$/&$*/" +} + +defstr() +{ # replace an empty string with a default + sed "s/^\$/$*/" +} + +slugify() +{ # turn a string into a slug + if [ "$#" -gt 0 ]; then + echo "$*" + else + cat + fi | + tr '[:upper:]' '[:lower:]' | + sed \ + -e 's/[[:punct:]]//g' \ + -e 's/[^[:alnum:]_]/-/g' \ + -e 's/-+/-/g' \ + -e 's/^-//' -e 's/-$//' +} + +recent_files() +{ # list files +# WARNING: find -printf is NOT posix :( + dir="$1" + shift + + find "$dir" -maxdepth 1 \ + -not -name '.*' "$@" \ + -printf '%T@\t%p\n' \ + | sort -nr \ + | cut -f2 +} + +maybe_expand() +{ # expand a file based on its metadata (or lack thereof) + F="${1:-$F}" + + expand="$(M expand "$F")" + if [ -z "$expand" ] || "$expand"; then + C "$F" | ./lht | X + else + C "$F" + fi +} + +#shellcheck disable=2120 +build() +{ # X on a file + F="${1:-$F}" + [ -f "$F" ] || return 1 + l "$F" + dir="$UNKO/$(N)" + rm -rf "$dir" + mkdir -p "$dir" + X "$UNKL" > "$dir/index.html" +} + +build_dir() +{ # build a directory + for F in "$UNKI/$1"/*; do + build || l "$F: not a file" + done +} + +listing() +{ # print a listing + p "" +} + + +### groupck() {