add static folder and better cp commands

This commit is contained in:
Jus de Patate_ 2019-12-04 11:57:33 -07:00
parent 9a42755a4e
commit 625e27d185
1 changed files with 23 additions and 15 deletions

38
mkhtml
View File

@ -8,10 +8,10 @@ echo " |_| |_| |_|_|\_\_| |_|\__|_| |_| |_|_|"
# http://patorjk.com/software/taag/
echo ""
if [[ -d "$(pwd)/pages/" && -d "$(pwd)/parts/" && -d "$(pwd)/builds/" ]]; then
PAGESDIR="$(pwd)/pages/"
PARTSDIR="$(pwd)/parts/"
BUILDSDIR="$(pwd)/builds/"
if [[ -d "$(pwd)/pages" && -d "$(pwd)/parts" && -d "$(pwd)/builds" ]]; then
PAGESDIR="$(pwd)/pages"
PARTSDIR="$(pwd)/parts"
BUILDSDIR="$(pwd)/builds"
# Check if mandatory folders exist, make variables if yes, create them if not.
fi
@ -21,7 +21,7 @@ if [ ! -w "$BUILDSDIR" ]; then
exit 1
fi
if [[ ! -d "$(pwd)/pages/" || ! -d "$(pwd)/parts/" || ! -d "$(pwd)/builds/" ]]; then
if [[ ! -d "$(pwd)/pages" || ! -d "$(pwd)/parts" || ! -d "$(pwd)/builds" ]]; then
mkdir {pages,parts,builds} 2>/dev/null
echo "pages, parts and builds folders were created by mkhtml in $(pwd)"
echo "now populate them"
@ -29,10 +29,14 @@ if [[ ! -d "$(pwd)/pages/" || ! -d "$(pwd)/parts/" || ! -d "$(pwd)/builds/" ]];
fi
if [ -d "$(pwd)/src/" ]; then
SRCDIR="$(pwd)/src/"
if [ -d "$(pwd)/src" ]; then
SRCDIR="$(pwd)/src"
fi
# Check if there is a src/ folder
if [ -d "$(pwd)/static" ]; then
STATDIR="$(pwd)/static"
fi
# Check if there is a static/ foder
echo "PAGESDIR: $PAGESDIR"
echo "PARTSDIR: $PARTSDIR"
@ -40,34 +44,38 @@ echo "BUILDSDIR: $BUILDSDIR"
if [ -n "$SRCDIR" ]; then
echo "SRCDIR: $SRCDIR"
fi
if [ -n "$STATDIR" ]; then
echo "STATDIR: $STATDIR"
fi
echo ""
echo "Building files..."
# https://stackoverflow.com/a/54563899
cd $PAGESDIR && find . -type f -print0 | while IFS= read -r -d $'\0' file; do
filename=$(echo $file | sed 's/.\///')
newloc="$BUILDSDIR$filename"
newloc="$BUILDSDIR/$filename"
touch $newloc 2>/dev/null
echo "Building $file"
echo "<!-- Built with mkhtml (https://tildegit.org/jusdepatate/mkhtml) -->" > "$newloc"
cat "$PARTSDIR/footer.html" >> "$newloc"
cat "$PAGESDIR$filename" >> "$newloc"
cat "$PAGESDIR/$filename" >> "$newloc"
cat "$PARTSDIR/header.html" >> "$newloc"
# build file using PARTS and PAGE
done
if [ -n "$SRCDIR" ]; then
echo "Copying SRCDIR to BUILDSDIR"
cp -r "$SRCDIR" "$BUILDSDIR"
mkdir "$BUILDSDIR/src" 2>/dev/null
cp -r $SRCDIR/* $BUILDSDIR/src
fi
if [ -n "$STATDIR" ]; then
echo "Copying STATDIR to BUILDSDIR"
cp -r $STATDIR/* $BUILDSDIR
fi
echo ""
echo "Looks like all files were built"
echo ""
if [ -z "$SRCDIR" ]; then
echo "Pro Tip: add a SRCDIR (create a src/ dir in $(pwd) for CSS/JS)"
fi
echo "Please report any error to https://tildegit.org/jusdepatate/mkhtml"