#!/usr/bin/env bash set -eu TPL=template.html OUT=public YT="https://www.youtube.com/@tony-btw" GH="https://github.com/tonybanters" fm() { awk 'NR==1&&$0=="---"{f=1;next} f&&$0=="---"{exit} f' "$1"; } field() { printf '%s\n' "$1" | sed -n "s/^$2: *//p" | head -1 | sed 's/^"//; s/"$//'; } tagsof() { printf '%s\n' "$1" | sed -n 's/^tags: *//p' | head -1 | tr -d '[]"' | tr ',' ' '; } esc() { printf '%s' "$1" | sed 's/&/\&/g; s//\>/g'; } fdate() { date -d "$1" +"%B %-d, %Y" 2>/dev/null || printf '%s' "$1"; } tslug() { printf '%s' "$1" | tr 'A-Z' 'a-z' | sed 's/[^a-z0-9]\{1,\}/-/g; s/^-//; s/-$//'; } render() { # out title section buffer showtitle(0|1) ; body on stdin out=$1; title=$2; sec=$3; buf=$4; show=$5; extra="" [ "$show" = 1 ] && extra="-M showtitle=true" mkdir -p "$(dirname "$out")" pandoc --template="$TPL" -s -M title="$title" -M section="$sec" -M buffer="$buf" $extra -o "$out" } tut_sorted() { for f in content/tutorial/*/index.md; do b=$(fm "$f"); printf '%s\t%s\n' "$(field "$b" date)" "$(basename "$(dirname "$f")")" done | sort -r } comm_sorted() { for f in content/community/*/index.md; do b=$(fm "$f"); printf '%s\t%s\n' "$(field "$b" date)" "$(basename "$(dirname "$f")")" done | sort -r } tut_card() { f="content/tutorial/$1/index.md"; b=$(fm "$f") img=$(field "$b" image); t=$(esc "$(field "$b" title)") d=$(fdate "$(field "$b" date)"); desc=$(esc "$(field "$b" description)") cat < $t
$t
$d
$desc
EOF } comm_card() { f="content/community/$1/index.md"; b=$(fm "$f") t=$(esc "$(field "$b" title)"); d=$(fdate "$(field "$b" date)") au=$(esc "$(field "$b" author)"); desc=$(esc "$(field "$b" description)") tags="" for tg in $(tagsof "$b"); do tags="$tags$(esc "$tg") " done cat <
by $au · $d
$desc
$tags
EOF } # ---------- home ---------- { cat <

Creating Quick and Painless Linux Tutorials

My name is Tony, and I encourage you all to visit the command line and learn how to maneuver the CLI. Installing Linux distributions, window managers, text editors, and more will help you grow not only as a developer, but as a computer enthusiast.

YouTube Channel Support! Github

Recent Tutorials

Stay tuned for new videos and writeups!

EOF tut_sorted | head -3 | while IFS="$(printf '\t')" read -r d s; do tut_card "$s"; done cat <
EOF } | render "$OUT/index.html" "Tony, btw." home index 0 # ---------- tutorial list ---------- { echo '
' tut_sorted | while IFS="$(printf '\t')" read -r d s; do tut_card "$s"; done echo '
' } | render "$OUT/tutorial/index.html" "Tutorials" tutorial index 1 # ---------- community list ---------- { echo '
' comm_sorted | while IFS="$(printf '\t')" read -r d s; do comm_card "$s"; done echo '
' } | render "$OUT/community/index.html" "Community" community index 1 # ---------- support ---------- { cat <
Subscribe on YouTube
Support the channel by subscribing — it's free and helps spread the word.

Go to YouTube

Donate via Square
Help keep the content flowing. Every contribution makes a difference.

Donate via Square

Support on Ko-Fi
Prefer Ko-Fi? Buy me a coffee and support future videos directly.

Go to Ko-Fi

EOF } | render "$OUT/support/index.html" "Support the Channel" support index 1 # ---------- tags ---------- tagdir=$(mktemp -d) for f in content/tutorial/*/index.md; do b=$(fm "$f"); s=$(basename "$(dirname "$f")") for tg in $(tagsof "$b"); do ts=$(tslug "$tg"); echo "tutorial:$s" >> "$tagdir/$ts"; echo "$tg" > "$tagdir/$ts.name"; done done for f in content/community/*/index.md; do b=$(fm "$f"); s=$(basename "$(dirname "$f")") for tg in $(tagsof "$b"); do ts=$(tslug "$tg"); echo "community:$s" >> "$tagdir/$ts"; echo "$tg" > "$tagdir/$ts.name"; done done index_body=$(mktemp) echo '
' > "$index_body" for tf in "$tagdir"/*; do case "$tf" in *.name) continue;; esac ts=$(basename "$tf"); name=$(cat "$tagdir/$ts.name"); n=$(wc -l < "$tf") printf '%s (%s)\n' "$ts" "$(esc "$name")" "$n" >> "$index_body" { echo '
' while IFS= read -r entry; do type=${entry%%:*}; sl=${entry#*:} [ "$type" = tutorial ] && tut_card "$sl" || comm_card "$sl" done < "$tf" echo '
' } | render "$OUT/tags/$ts/index.html" "#$name" tags "$ts.org" 1 done echo '
' >> "$index_body" render "$OUT/tags/index.html" "Tags" tags index 1 < "$index_body" rm -rf "$tagdir" "$index_body" echo "generated home, lists, support, tags"