From 52e9c3aeea18d5750fea8704711a113adae93903 Mon Sep 17 00:00:00 2001 From: davidovski Date: Mon, 12 Jun 2023 03:57:18 +0100 Subject: create example site where every page is executed to generate itself --- src/shblg | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) mode change 100644 => 100755 src/shblg (limited to 'src/shblg') diff --git a/src/shblg b/src/shblg old mode 100644 new mode 100755 index ff10250..226216c --- a/src/shblg +++ b/src/shblg @@ -7,7 +7,9 @@ PAGE_TEMPLATE=blog/template.html while getopts ":o:i:t:" opt; do case "$opt" in o) - OUTPUT_DIR=$(realpath $OPTARG) + OUTPUT_DIR=$OPTARG/ + mkdir -p $OUTPUT_DIR + OUTPUT_DIR=$(realpath $OUTPUT_DIR) ;; i) INPUT_DIR=$(realpath $OPTARG) @@ -18,6 +20,29 @@ while getopts ":o:i:t:" opt; do esac done -for f in ${INPUT_DIR}/*.md; do - md2html "$f" > ${OUTPUT_DIR}/$f -done +# process a file to +process () { + path="${1#$INPUT_DIR}" + dirpath="${1%${1##*/}}" + out_file="${OUTPUT_DIR}${path}" + + [ -d "$1" ] && { + mkdir -p "$out_file" + for f in "$1"/*; do + process "$f" + done + return 0 + } || [ -x "$1" ] && { + # execute the file + cd $dirpath + "$1" > "${out_file%.*}.html" + cd - + return 0 + } || { + # just output the file as is + while IFS= read -r line; do printf "%s\n" "$line"; done < "$1" > "$out_file" + return 0 + } +} + +process "$INPUT_DIR" -- cgit v1.2.1