render_tree: copy non-markdown files, don't render

Also add newlines to all instances of printf, and
fix one printf call that was not being redirected
to stderr
This commit is contained in:
Gender Demon 2021-01-01 20:21:58 +00:00
parent dc63a4059b
commit cc4425872d
1 changed files with 16 additions and 6 deletions

View File

@ -12,15 +12,25 @@ traverse_dir() {
# Recurse into directories in the given directory
if [ -d "$file" ]
then
printf '%s is a directory, recursing...' "$file" >&2
printf '%s is a directory, recursing...\n' "$file" >&2
traverse_dir "$file" "$2"
elif [ -f "$file" ]
then
printf 'Rendering %s...' "$file" >&2
# Use basename to strip the .md suffix from markdown files, then
# append .html
name="$(basename -s .md "$file")"
./render_file "$file" > "$2"/"$name".html
# 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")"
./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
}