summaryrefslogtreecommitdiffstats
path: root/gen.sh
diff options
context:
space:
mode:
authorTyler Davis <tyler@gluecode.net>2025-03-04 19:36:15 +0000
committerTyler Davis <tyler@gluecode.net>2025-03-04 19:36:15 +0000
commitb7354ac9db8cca1742bffc13b4fa96bfdf6bd263 (patch)
treeab8936afafea25e4f3d9e15911babdc77f84d0c9 /gen.sh
parentb26044cfbd391c2aec809f4193fc967fae2ee9aa (diff)
downloadjournal-b7354ac9db8cca1742bffc13b4fa96bfdf6bd263.tar.gz
journal-b7354ac9db8cca1742bffc13b4fa96bfdf6bd263.zip
gen: more fixes to output
Diffstat (limited to 'gen.sh')
-rwxr-xr-xgen.sh11
1 files changed, 8 insertions, 3 deletions
diff --git a/gen.sh b/gen.sh
index d2cf21c..847ce78 100755
--- a/gen.sh
+++ b/gen.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env sh
WORKDIR=$PWD
-OUTDIR=/var/www/blog/
+OUTDIR=/var/www/blog
verbose=0 # Variables to be evaluated as shell arithmetic should be initialized to a default or validated beforehand.
if [ ! "$(command -v lowdown)" ]; then
@@ -84,19 +84,25 @@ EOF
# Make out dir
if [ ! -d "${OUTDIR}" ]; then mkdir ${OUTDIR} ; fi
+# Remove posts and drafts if present
+if [ -d "${OUTDIR}/posts" ]; then rm -rf "${OUTDIR}/posts" ; fi
+if [ -d "${OUTDIR}/draft" ]; then rm -rf "${OUTDIR}/draft" ; fi
+
MDLIST=$(eval "find ${WORKDIR} -type f -name \"*.md\" ")
for m in $MDLIST; do
# shortpath trims the working directory prefix
shortpath=$(eval "echo $m | sed -e 's,${WORKDIR}/,,' ")
BNAME=$(eval "basename $m")
- dirpath=$(eval "echo $m | sed -e 's,${WORKDIR}/,,' -e 's,${BNAME},,' ")
+ dirpath=$(eval "dirname $shortpath")
filename=$(eval "echo ${BNAME} | sed -e 's,\.md,,' ")
if [ $verbose -gt 0 ]; then
echo "Processing: ${shortpath}"
fi
+
OUTPATH="${OUTDIR}/${dirpath}/${filename}.html"
+ if [ ! -d "${OUTDIR}/${dirpath}" ]; then mkdir -p "${OUTDIR}/${dirpath}" ; fi
# Output directly to file if $dirpath ends in ".md" for root-level files
case $dirpath in *.md)
@@ -105,7 +111,6 @@ for m in $MDLIST; do
*)
# Make the outdir if not ending in ".md"
- if [ ! -d "${OUTDIR}/${dirpath}" ]; then mkdir ${OUTDIR}/${dirpath} ; fi
esac
echo $HEADER > "${OUTPATH}"