summaryrefslogtreecommitdiff
path: root/src/shblg
diff options
context:
space:
mode:
Diffstat (limited to 'src/shblg')
-rwxr-xr-x[-rw-r--r--]src/shblg33
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"