diff options
author | davidovski <david@davidovski.xyz> | 2023-06-12 04:02:07 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2023-06-12 04:02:07 +0100 |
commit | 50074253d03d2f8568d44fd931b84ce212156be9 (patch) | |
tree | 2d0de0b1ef7bd0f122d2c2de3cbc3643253c98eb /src/shblg.sh | |
parent | 52e9c3aeea18d5750fea8704711a113adae93903 (diff) |
add install script to install
Diffstat (limited to 'src/shblg.sh')
-rwxr-xr-x | src/shblg.sh | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/shblg.sh b/src/shblg.sh new file mode 100755 index 0000000..226216c --- /dev/null +++ b/src/shblg.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +INPUT_DIR=blog +OUTPUT_DIR=dist +PAGE_TEMPLATE=blog/template.html + +while getopts ":o:i:t:" opt; do + case "$opt" in + o) + OUTPUT_DIR=$OPTARG/ + mkdir -p $OUTPUT_DIR + OUTPUT_DIR=$(realpath $OUTPUT_DIR) + ;; + i) + INPUT_DIR=$(realpath $OPTARG) + ;; + t) + PAGE_TEMPLATE=$(realpath $OPTARG) + ;; + esac +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" |