diff --git a/render_file b/render_file index 1469ce6..76122dc 100755 --- a/render_file +++ b/render_file @@ -3,6 +3,9 @@ # arguments: # $1: markdown file to render +# Determine location of this script +script_dir=$(dirname "$0") + # Separate metadata and actual markdown in the .md file frontmatter=$(awk '/!startmeta/,/!endmeta/ {if ($0 != "!startmeta" && $0 != "!endmeta") print;}' "$1") docbody=$(awk '/!endmeta/ {p=1; next} p' "$1") @@ -13,17 +16,17 @@ date=$(echo "$frontmatter" | awk -F'=' '/date=/ {print $2}') if [ -f gentemplate/header ] then printf 'Generating page header...' >&2 - title="$title" date="$date" gentemplate/header + title="$title" date="$date" "$script_dir"/gentemplate/header fi if [ -f gentemplate/footer ] then printf 'Generating page footer...' >&2 - date="$date" gentemplate/footer + date="$date" "$script_dir"/gentemplate/footer fi if [ -f gentemplate/htmlhead ] then printf 'Generating page ...' >&2 - title="$title" gentemplate/htmlhead + title="$title" "$script_dir"/gentemplate/htmlhead fi # cmark doesn't create the , doctype declaration or indeed most of the document # structure for us, so we'll do it ourselves. @@ -33,12 +36,12 @@ printf '\n' printf '\n' printf '\n' # At this point, insert the -printf "%s\n" "$(cat template/htmlhead)" +printf "%s\n" "$(cat "$script_dir"/template/htmlhead)" printf '\n' printf '\n' printf '
\n' # Now insert the header -printf "%s\n" "$(cat template/header)" +printf "%s\n" "$(cat "$script_dir"/template/header)" printf '
\n' printf '
\n' # Now we insert the main content of the page @@ -47,7 +50,7 @@ printf '%s' "$(echo "$docbody" | cmark)" printf '
\n' # Finally, the footer printf '\n' printf '\n' printf '\n' diff --git a/render_tree b/render_tree index 5ef7814..375ac2d 100755 --- a/render_tree +++ b/render_tree @@ -5,6 +5,10 @@ # $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"/* @@ -25,7 +29,7 @@ traverse_dir() { # Use basename to strip the .md suffix from markdown files, then # append .html name="$(basename -s .md "$file")" - ./render_file "$file" > "$2"/"$name".html + "$script_dir"/render_file "$file" > "$2"/"$name".html else printf '%s is not markdown, copying...\n' "$file" >&2 name="$(basename "$file")"