Make it possible to run wordpusher from outside of its directory
This commit is contained in:
parent
2ef8fe251d
commit
f850eff6ff
15
render_file
15
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 <head>...' >&2
|
||||
title="$title" gentemplate/htmlhead
|
||||
title="$title" "$script_dir"/gentemplate/htmlhead
|
||||
fi
|
||||
# cmark doesn't create the <head>, doctype declaration or indeed most of the document
|
||||
# structure for us, so we'll do it ourselves.
|
||||
|
@ -33,12 +36,12 @@ printf '<!doctype html>\n'
|
|||
printf '<html>\n'
|
||||
printf '<head>\n'
|
||||
# At this point, insert the <head>
|
||||
printf "%s\n" "$(cat template/htmlhead)"
|
||||
printf "%s\n" "$(cat "$script_dir"/template/htmlhead)"
|
||||
printf '</head>\n'
|
||||
printf '<body>\n'
|
||||
printf '<header>\n'
|
||||
# Now insert the header
|
||||
printf "%s\n" "$(cat template/header)"
|
||||
printf "%s\n" "$(cat "$script_dir"/template/header)"
|
||||
printf '</header>\n'
|
||||
printf '<main>\n'
|
||||
# Now we insert the main content of the page
|
||||
|
@ -47,7 +50,7 @@ printf '%s' "$(echo "$docbody" | cmark)"
|
|||
printf '</main>\n'
|
||||
# Finally, the footer
|
||||
printf '<footer>\n'
|
||||
printf '%s\n' "$(cat template/footer)"
|
||||
printf '%s\n' "$(cat "$script_dir"/template/footer)"
|
||||
printf '</footer>\n'
|
||||
printf '</body>\n'
|
||||
printf '</html>\n'
|
||||
|
|
|
@ -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")"
|
||||
|
|
Loading…
Reference in New Issue