Kickstarting with Swift
The earlier iteration behind this domain was a monster-ish production. It had:
- the top-level website for my apps that I made using Hype
- a defunct blog produced by Hugo
- my visualization projects, for git repository exploration and BART real time departures, both of which were big, separate apps.
- GitViz was in Python and BARTUp was in Clojure/Clojurescript (later the backend was in Go, because JVM is resource heavy and I was relying on a cheap DigitalOcean droplet).
nginx configuration was a huge mess and I was afraid to touch anything.
The complexity was wearing me down and I had moved on from the visualization projects. So the blog, and this website stayed neglected. But earlier this year I decided to write more: about Swift and programming general, working on side projects, Urdu, books I was reading, and a lot more.
I decided to stop hosting the visualization projects, and go with a simpler web presence (a marketing site, if you will).
What I wanted:
- a single, static site, generated mostly from Markdown content
- including a blog
- easy CSS customization
- simplest possible setup. I really don't need an assets pipeline!
What does a software engineer do at this point?
Writing a custom static-site generator in Swift
I have been building server-side apps in Swift for a while. I built a web app for ingesting and serving podcast content for a defunct iOS app; a bot that interfaces between GitHub webhooks and Asana (at work), and some other less complex bits and pieces. And I have come to love server-side Swift. I could probably get working code done faster in Python or Clojure specially with robust libraries being available. But I am much more comfortable now with writing business logic in Swift. (And if most the code you write is not business logic, is that project really worth it?)
So I built a static site generator in Swift, that I called Taan. I had fun building a quick & dirty solution that produces an output that is just right for me.
Some interesting bits:
- It's very opinionated (i.e., exactly what I need, nothing more). It expects to produce a blog, for example.
- I am using a fork of Down for Markdown → HTML processing. The original does not support Swift Package Manager (SPM), while mine only supports SPM.
- command line options parsing is via SPM's Argument Parser
- once you run the tool via
swift run, it will watch for file changes and rebuild the site. I wrote a messy, recursive file system watcher using Dispatch Source. I am going to look into replacing it with SPM's FSWatch later.
- HTML template views use Vapor's Leaf
- Prism handles code syntax highlighting by styling CSS classes emitted by Down (CommonMark).
I have several other things in store, specially tags and posts chronology.