commit 901b7e7af943702e9f3277ee69ef903a7fe860d7
parent 2bf8926cbebb1bd8cbcb4e0ea45f6e2c7009bb5c
Author: alex wennerberg <alex@alexwennerberg.com>
Date: Sat, 8 Apr 2023 15:00:20 -0400
Update build script
- simplify
- POSIX
- allow subdirs
Diffstat:
2 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/build.sh b/build.sh
@@ -1,34 +1,43 @@
-#!/bin/bash
+#!/bin/sh
+
+# How it works:
+# Delete everything in site dir
+# first, build nav html string
+# lists all files recursively in srcdir
+# copies them to outdir if not html
+# otherwise, add header and footer
+# TODO: add sections in sidebar, maybe clean names
outdir=_site
+srcdir=src
mkdir -p $outdir
+rm -rf $outdir/*
-# build nav
+htmlfiles=$(find $srcdir -name '*.html')
function nav () {
echo "<nav><ul><section class='site-nav'>"
- for file in ./src/*.html; do
+ for file in $htmlfiles; do
fn=`basename ${file%.*}`
- echo "<li><a href='`basename $file`'>$fn</a></li>"
+ realpath=`echo $file | sed -e "s/^${srcdir}\///"`
+ echo "<li><a href='/$realpath'>${realpath%.*}</a></li>"
done
echo "</section></ul></nav><main>"
}
navstr=`nav`
-# copy over files
-for i in ./src/*; do
- if [[ $i == *.html ]]
- then
- a=`basename ${i%.*}`
- fn=$outdir/$a.html
+for file in $(find $srcdir); do
+ realpath=`echo $file | sed -e "s/^${srcdir}\///"`
+ fn=$outdir/$realpath
+ mkdir -p `dirname $fn`
+ if [[ $file == *.html ]]; then
cat templates/header.html > $fn
echo $navstr >> $fn
- cat $i >> $fn
+ cat $file >> $fn
cat templates/footer.html >> $fn
- else
- b=`basename $i`
- cp $i $outdir/$b;
+ else
+ cp $file $fn 2> /dev/null
fi
done
diff --git a/templates/header.html b/templates/header.html
@@ -2,10 +2,10 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
- <link rel="stylesheet" type="text/css" href="./style.css">
+ <link rel="stylesheet" type="text/css" href="/style.css">
</head>
<header>
- <table><tr><td><a href="/"><img src="icon.png" width=80 /></a></td>
+ <table><tr><td><a href="/"><img src="/icon.png" width=80 /></a></td>
<td><h1>alexw.nyc</h1></td></tr></table>
</header>
<body>