diff options
author | davidovski <david@davidovski.xyz> | 2023-06-12 03:57:18 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-06-12 03:57:18 +0100 |
commit | 52e9c3aeea18d5750fea8704711a113adae93903 (patch) | |
tree | f8a9d31de26ed8d0b2ffe6515f2302c0d1374ea1 /src/shblg | |
parent | af75a700c52aaca66ffe6db42c4448c2070be21a (diff) |
create example site where every page is executed to generate itself
Diffstat (limited to 'src/shblg')
-rwxr-xr-x[-rw-r--r--] | src/shblg | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/shblg b/src/shblg index ff10250..226216c 100644..100755 --- 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" |