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:
|
# arguments:
|
||||||
# $1: markdown file to render
|
# $1: markdown file to render
|
||||||
|
|
||||||
|
# Determine location of this script
|
||||||
|
script_dir=$(dirname "$0")
|
||||||
|
|
||||||
# Separate metadata and actual markdown in the .md file
|
# Separate metadata and actual markdown in the .md file
|
||||||
frontmatter=$(awk '/!startmeta/,/!endmeta/ {if ($0 != "!startmeta" && $0 != "!endmeta") print;}' "$1")
|
frontmatter=$(awk '/!startmeta/,/!endmeta/ {if ($0 != "!startmeta" && $0 != "!endmeta") print;}' "$1")
|
||||||
docbody=$(awk '/!endmeta/ {p=1; next} p' "$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 ]
|
if [ -f gentemplate/header ]
|
||||||
then
|
then
|
||||||
printf 'Generating page header...' >&2
|
printf 'Generating page header...' >&2
|
||||||
title="$title" date="$date" gentemplate/header
|
title="$title" date="$date" "$script_dir"/gentemplate/header
|
||||||
fi
|
fi
|
||||||
if [ -f gentemplate/footer ]
|
if [ -f gentemplate/footer ]
|
||||||
then
|
then
|
||||||
printf 'Generating page footer...' >&2
|
printf 'Generating page footer...' >&2
|
||||||
date="$date" gentemplate/footer
|
date="$date" "$script_dir"/gentemplate/footer
|
||||||
fi
|
fi
|
||||||
if [ -f gentemplate/htmlhead ]
|
if [ -f gentemplate/htmlhead ]
|
||||||
then
|
then
|
||||||
printf 'Generating page <head>...' >&2
|
printf 'Generating page <head>...' >&2
|
||||||
title="$title" gentemplate/htmlhead
|
title="$title" "$script_dir"/gentemplate/htmlhead
|
||||||
fi
|
fi
|
||||||
# cmark doesn't create the <head>, doctype declaration or indeed most of the document
|
# cmark doesn't create the <head>, doctype declaration or indeed most of the document
|
||||||
# structure for us, so we'll do it ourselves.
|
# structure for us, so we'll do it ourselves.
|
||||||
|
@ -33,12 +36,12 @@ printf '<!doctype html>\n'
|
||||||
printf '<html>\n'
|
printf '<html>\n'
|
||||||
printf '<head>\n'
|
printf '<head>\n'
|
||||||
# At this point, insert the <head>
|
# At this point, insert the <head>
|
||||||
printf "%s\n" "$(cat template/htmlhead)"
|
printf "%s\n" "$(cat "$script_dir"/template/htmlhead)"
|
||||||
printf '</head>\n'
|
printf '</head>\n'
|
||||||
printf '<body>\n'
|
printf '<body>\n'
|
||||||
printf '<header>\n'
|
printf '<header>\n'
|
||||||
# Now insert the header
|
# Now insert the header
|
||||||
printf "%s\n" "$(cat template/header)"
|
printf "%s\n" "$(cat "$script_dir"/template/header)"
|
||||||
printf '</header>\n'
|
printf '</header>\n'
|
||||||
printf '<main>\n'
|
printf '<main>\n'
|
||||||
# Now we insert the main content of the page
|
# Now we insert the main content of the page
|
||||||
|
@ -47,7 +50,7 @@ printf '%s' "$(echo "$docbody" | cmark)"
|
||||||
printf '</main>\n'
|
printf '</main>\n'
|
||||||
# Finally, the footer
|
# Finally, the footer
|
||||||
printf '<footer>\n'
|
printf '<footer>\n'
|
||||||
printf '%s\n' "$(cat template/footer)"
|
printf '%s\n' "$(cat "$script_dir"/template/footer)"
|
||||||
printf '</footer>\n'
|
printf '</footer>\n'
|
||||||
printf '</body>\n'
|
printf '</body>\n'
|
||||||
printf '</html>\n'
|
printf '</html>\n'
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
# $1: input directory path
|
# $1: input directory path
|
||||||
# $2: output 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() {
|
traverse_dir() {
|
||||||
# Iterate over files in the given directory
|
# Iterate over files in the given directory
|
||||||
for file in "$1"/*
|
for file in "$1"/*
|
||||||
|
@ -25,7 +29,7 @@ traverse_dir() {
|
||||||
# Use basename to strip the .md suffix from markdown files, then
|
# Use basename to strip the .md suffix from markdown files, then
|
||||||
# append .html
|
# append .html
|
||||||
name="$(basename -s .md "$file")"
|
name="$(basename -s .md "$file")"
|
||||||
./render_file "$file" > "$2"/"$name".html
|
"$script_dir"/render_file "$file" > "$2"/"$name".html
|
||||||
else
|
else
|
||||||
printf '%s is not markdown, copying...\n' "$file" >&2
|
printf '%s is not markdown, copying...\n' "$file" >&2
|
||||||
name="$(basename "$file")"
|
name="$(basename "$file")"
|
||||||
|
|
Loading…
Reference in New Issue