commit 6dae576a64bce908bc4511921b5861f03a01f2cd
parent 5dc46d61add7bfa6716423653a8a8152c7fc93e0
Author: Jake Bauer <jbauer@paritybit.ca>
Date: Fri, 9 Aug 2019 23:16:26 -0400
Prevent compilation of a page with the name ""
(Also improve code readability by changing the name of a single
variable)
Diffstat:
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/createpages.sh b/createpages.sh
@@ -41,15 +41,15 @@ echo "Building $@..."
for page in $@; do
pagename=$(basename $page | cut -f 1 -d '.')
- filepath=$(dirname $page)
- checkpage=$(echo $filepath | cut -f 1 -d '/')
+ pagedir=$(dirname $page)
+ checkpage=$(echo $pagedir | cut -f 1 -d '/')
# Stripts "pages" from the file path so files are saved in the root of
# $htmldir
- if [[ "$filepath" == "pages" ]]; then
+ if [[ "$pagedir" == "pages" ]]; then
savepath="."
elif [[ "$checkpage" == "pages" ]]; then
- savepath=$(echo ${filepath#$checkpage/})
+ savepath=$(echo ${pagedir#$checkpage/})
fi
if [[ ! -d "$htmldir/$savepath" ]]; then
@@ -57,11 +57,11 @@ for page in $@; do
mkdir -p build/$savepath
fi
- if [[ "$page" != "" && ! -d $page ]]; then
+ if [[ "$page" != "" && ! -d $page && "$pagename" != "" ]]; then
echo "=====Creating $htmldir/$savepath/$pagename.html====="
echo " Compiling page content..."
- markdown $filepath/$pagename.md > build/$savepath/$pagename-content.html
+ markdown $pagedir/$pagename.md > build/$savepath/$pagename-content.html
echo " Constructing full page..."
> $htmldir/$savepath/$pagename.html
@@ -71,14 +71,14 @@ for page in $@; do
# Assumes first line of every markdown file is the header in the format:
# "## Title of The Page"
- pagetitle=$(head -n 1 $filepath/$pagename.md | cut -f 2- -d " ")
+ pagetitle=$(head -n 1 $pagedir/$pagename.md | cut -f 2- -d " ")
echo " Setting page title..."
sed -i "s/<title>.*<\/title>/<title>paritybit.ca – ${pagetitle//&/\\&}<\/title>/" \
$htmldir/$savepath/$pagename.html
# Assumes the third line of every markdown file is the <meta> tag
# information (preceded by [//]: #
- metatext=$(sed '3!d' $filepath/$pagename.md | cut -d# -f 2)
+ metatext=$(sed '3!d' $pagedir/$pagename.md | cut -d# -f 2)
# Remove leading whitespace
metatextclean=$(echo -e "${metatext}" | sed -e 's/^[[:space:]]*//')
echo " Setting meta tag..."