alexkarle.com

Source for alexkarle.com
git clone git://git.alexkarle.com/alexkarle.com.git
Log | Files | Refs | README | LICENSE

genpage (1237B) [raw]


      1 #!/bin/sh
      2 # nihdoc -> html with header and footer
      3 
      4 [ -z "$1" ] && echo "usage: genpage FILE" 1>&2 && exit 1
      5 
      6 REPO=$(dirname "$(dirname "$0")")
      7 GITDIR=${GITDIR:-$REPO}
      8 title=$(grep '^# ' "$1" | cut -c3- | tr -d '`*_')
      9 
     10 cat <<EOM
     11 <!DOCTYPE html>
     12 <html lang="en">
     13 <head>
     14 <meta charset="utf-8"/>
     15 <meta name="viewport" content="width=device-width,initial-scale=1">
     16 <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
     17 <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
     18 <!-- Inspired by https://www.swyx.io/css-100-bytes/ -->
     19 <style>
     20 EOM
     21 cat "$REPO/www/style.css"
     22 cat <<EOM
     23 </style>
     24 <title>$title | alexkarle.com</title>
     25 </head>
     26 <body>
     27 <nav>
     28 EOM
     29 
     30 dir=$(dirname "/$1")
     31 if [ $(basename "$1") = "index.txt" ]; then
     32 	dir=$(dirname $dir)
     33 fi
     34 
     35 while [ "$dir" != "/" ]; do
     36 	part=$(basename $dir)
     37 	path=${dir##/www}
     38 	if [ -z "$path" ]; then
     39 		path="/"
     40 	fi
     41 	echo " / <a href=\"$path\">$part</a>" | sed 's/www/home/'
     42 	dir=$(dirname $dir)
     43 done | sed -n '1!G;h;$p' # reverse lines
     44 
     45 echo '</nav>'
     46 
     47 nihdoc < "$1"
     48 
     49 cat <<EOM
     50 <footer>
     51 <br>
     52 <em>Last Updated: $(git -C "$GITDIR" log --pretty="%cs" -n 1 -- "$1")
     53 (<a href="/license.html">License</a>)</em>
     54 </footer>
     55 </body>
     56 </html>
     57 EOM
     58 
     59 cat <<EOM
     60 </body>
     61 </html>
     62 EOM