Devlog: Blogging Tools — Category Fixer
I was going to say that this one was pretty quick to implement, but thinking of it now, it took several hours all up, so maybe it wasn’t that quick. It’s a feature I’ve creatively called the “category fixer”. Yeah, the name’s not great, but it’s been a feature I’ve been wishing for a while, and it’s nice to see it added to Blogging Tools.
I post blog posts of images which could either be a photo or a screenshot, along with the occasional meme. I have categories for all three, and when I create a new post with an image, I try to make sure the appropriate category is set. Only issue is that I usually forget, and most image posts remain without any category at all. Micro.blog does has a feature of automatically adding posts with image tags into a photos category, but I’ve turned that off as I don’t like the idea of screenshots going there.
So I needed a way to fix this, and that’s what this new feature does. I’ve added a RSS feed parser which will poll my blog’s RSS feed for any new or updated posts. If there are any, the HTML content will get parsed to find at least one img
. If it does, an in-app notification will be added. I can then go in and triage these posts, selecting the category they should be sorted into.
About half the work was building out these in-app notifications. They’re all stored in a sqlite3
table and mainly consist of a notification type, brief message, and an extendable set of properties which are stored as a JSON object.
For the feed parser, I’m using gofeed, the same library I’m using for reading podcast feeds. I can definitely recommend this library for parsing RSS feeds if you’re using Golang. There was a little bit I had to add around this library to detect when feed items have previously been read or updated. The way I’m detecting this is by recording the GUID, along with a SHA-1 hash of the title, description, and content in the database. Parsing the feed HTML is done using goquery, allowing me to easily select the first img
tag of a HTML fragment. For fetching and setting the categories, I’m using a home grown Micropub client.
So that’s “category fixer”. A lot of infrastructure was added for this one which could be useful in the future. I do have some other ideas that would follow this sort of pattern: a new post is picked up by the RSS reader, and an in-app notification is raised for me to action. I suspect this may becoming a bit of a pattern.