# list available commands and exit
default:
  @just --list --unsorted

# build rss feed
rss:
  #!/bin/sh
  exec > feed.xml
  echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">"
  echo "  <channel>"
  echo "    <title>It's Pro Toad and Superb Owl</title>"
  echo "    <link>https://git.tilde.town/dozens/protoadandsuperbowl</link>"
  echo "    <description>It's Pro Toad and Superb Owl!</description>"
  echo "    <atom:link rel=\"self\" type=\"application/rss+xml\" href=\"https://git.tilde.town/dozens/protoadandsuperbowl/raw/branch/master/feed.xml\"/>"
  echo "    <generator>/bin/sh</generator>"
  recsel db/database.rec | recfmt -f templates/feed.tmpl
  echo "</channel></rss>"

# watch toad.md for changes
watch:
  echo "TODO"
alias dev := watch

# build markdown comics
markdown:
  #!/bin/sh
  for ((i = 0; i < $(recsel -c db/database.rec); i++))
  do
    id=$(recsel -P id -n $i db/database.rec)
    recsel -n $i db/database.rec | recfmt -f templates/page.tmpl | fold -s -w 40 > $id.md
  done

# build gemini
gemini:
  #!/bin/sh
  for ((i = 0; i < $(recsel -c db/database.rec); i++))
  do
    id=$(recsel -P id -n $i db/database.rec)
    exec > gemini/$id.gmi
    echo "# $id"
    echo
    recsel -n $i db/database.rec | recfmt -f templates/page.tmpl | fold -s -w 40
    echo
    echo "=> gemini://tilde.town/~dozens/comic"
  done

# build gemini index
index:
  #!/bin/sh
  exec > gemini/index.gmi
  echo "# Pro Toad and Superb Owl"
  echo
  echo "Two best friends have adventures!"
  echo
  recsel db/database.rec \
  | recfmt "=> {{{{id}}.gmi {{{{date}} - {{{{id}}---" \
  | sed 's/---/\n/g' \
  | tail -r
  echo
  echo "=> gemini://tilde.town/~dozens/comic"

# go gemini
upload:
  rsync -vurp gemini/* $HOME/blogs/gemini/comic
  
# build and rss
all: markdown gemini index upload rss