# show all commands
default:
  just --list --unsorted

# build htmls
html:
  make

# dev
dev:
  ls src/*.md | entr just html

# copy assets to www
assets:
  cp assets/* www/

alias all := up
# upload it
up: html rss
  rsync -azP --exclude=.git www/* tilde:public_html/clericthief/

# make episodes rss
episoderss:
  #!/usr/bin/env zsh
  echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>cleric + thief</title>' > www/episodes.xml
  echo '<link>http://tilde.town/~dozens/clericthief/index.html</link><description>adventures of iofi and maddox</description><atom:link rel="self" type="application/rss+xml" href="http://tilde.town/~dozens/clericthief/episodes.xml"/>' >> www/episodes.xml
  ed -s << HEREDOC src/index.md | recfmt -f templates/blogitem.rec.template | m4 >> www/episodes.xml
  /BEGIN/ka
  /END/kb
  1,'ad
  'b,d
  %s/^- //
  %s,<time>\(.*\)</time>,time: \1|,
  %s, - \[\(.*\)\],title: \1|,
  %s,(\(.*\))$,source: \1|link: \1|,
  %s/html/md/
  %s/|/\\
  /g
  ,w /dev/stdout
  Q
  HEREDOC
  echo '</channel></rss>' >> www/episodes.xml

# make journal rss
journalrss:
  #!/usr/bin/env zsh
  echo '<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>cleric + thief</title>' > www/journal.xml
  echo '<link>http://tilde.town/~dozens/clericthief/index.html</link><description>behind the scenes of cleric + thief</description><atom:link rel="self" type="application/rss+xml" href="http://tilde.town/~dozens/clericthief/journal.xml"/>' >> www/journal.xml
  ed -s !'markdown src/journal.md' << HEREDOC | recfmt -f templates/journalitem.rec.template | m4 >> www/journal.xml
  /BEGIN/ka
  /END/kb
  1,'ad
  'b,d
  g/^<h2>/+s/^/note: /
  v/^note/s/^/+ /
  %s/+ <h2>/<h2>/
  %s_^<h2><time>\(.*\)</time> - \(.*\)</h2>_\\
  time: \1\\
  title: \2_
  g/^+ $/d
  ,w /dev/stdout
  Q
  HEREDOC
  echo '</channel></rss>' >> www/journal.xml

# build all rss
rss: episoderss journalrss

# one random NPC
npc:
  @recsel -P name,note -m 1 db/npc.rec

# one random plot thread
thread:
  @recsel -P name,note -m 1 db/threads.rec
