44 lines
1.4 KiB
Bash
Executable File
44 lines
1.4 KiB
Bash
Executable File
#!/bin/sh
|
|
# render_tree: render all the files in a directory tree to html or just copy them
|
|
# if they are not markdown
|
|
# arguments:
|
|
# $1: input directory path
|
|
# $2: output directory path
|
|
|
|
# Determine the location of render_file based on the location
|
|
# of this script
|
|
script_dir=$(dirname "$0")
|
|
|
|
traverse_dir() {
|
|
# Iterate over files in the given directory
|
|
for file in "$1"/*
|
|
do
|
|
# Recurse into directories in the given directory
|
|
if [ -d "$file" ]
|
|
then
|
|
printf '%s is a directory, recursing...\n' "$file" >&2
|
|
traverse_dir "$file" "$2"
|
|
elif [ -f "$file" ]
|
|
then
|
|
# If the file ends in .md, assume it's a markdown file and
|
|
# pass it as an argument to render_file, else just copy it straight
|
|
# from the input directory to the output directory
|
|
if basename "$file" | grep -q "\.md$"
|
|
then
|
|
printf 'Rendering %s...\n' "$file" >&2
|
|
# Use basename to strip the .md suffix from markdown files, then
|
|
# append .html
|
|
name="$(basename -s .md "$file")"
|
|
"$script_dir"/render_file "$file" > "$2"/"$name".html
|
|
else
|
|
printf '%s is not markdown, copying...\n' "$file" >&2
|
|
name="$(basename "$file")"
|
|
cp "$file" "$2"/"$name"
|
|
fi
|
|
fi
|
|
done
|
|
}
|
|
|
|
traverse_dir "$1" "$2"
|
|
printf 'Done.\n' >&2
|