Featured Images for the Blog API, With Credit Where It's Due
Posts on loadout.ca are mostly written and published through an API. They now carry a featured image, plus the fields to credit a photographer properly when the image isn't ours.
Most posts on this blog don't get written in an admin screen. They're drafted in markdown and sent to the site's own REST API: create a draft, review it, publish it. It's the same API that handles tickets, invoices and time tracking for Loadout.
Until this month, a post through the API couldn't have a hero image. Games posts without a picture of the game at the top looked unfinished, so that had to change.
Four new fields
The post object now accepts:
featured_image_urlfeatured_image_sourcefeatured_image_photographerfeatured_image_photographer_url
The first is the obvious one. The other three exist because not every image is ours. When a post uses a stock photo from somewhere like Unsplash, the photographer gets named and linked under the image, the way Unsplash asks. Making credit a field rather than a line someone has to remember to type means it actually happens.
For our own game screenshots, there's nothing to credit, so only the URL is set.
Where the images live
There's no upload endpoint. Images for posts live in the repo under public/, get committed alongside the work they illustrate, and deploy with the site. The API just points at https://loadout.ca/.... That keeps the post's assets versioned with the code, and means a post can never reference an image that only exists on someone's laptop.
Shipped with tests
The change was small: four new columns, the API accepting and returning them, and tests to keep it that way.
Then it went out the usual way: push to main, CI runs, Kamal deploys. After it was live, every game post got its hero image set through the same API.
It's a tiny feature. It's also the difference between a blog that looks maintained and one that looks like a changelog.