Ogre Codes

Follow @ogre_codes to get notified when new articles are posted to this site.

👨🏻‍💻

Blogging About Creating a Blogging Application So I can Blog 👨🏻‍💻

Jan 19, 2017 at 10:10 AM

I've been experimenting with Swift and iOS programming for a few years now, but due to time and laziness, I've never really found something I could build which I could bring myself to finish. Great ideas I thought I could turn into apps existed already or required piles of work to do. So finally I decided I would build something I could use personally and I just don't care if it's duplicated or triplicated in the app store already.

The concept here is simple, "Build a blogging app for my iPhone and iPad." As far as actual implementation goes, there is a bit of a twist. Rather than writing a blogging app that uploads to WordPress, Squarespace, or some other platform, what if the application were to build it in such a way that it just uploads the files directly to a web host via ssh or rsync? This is the old (old!) school approach, the pages are generated locally, templates for headers and footers applied in advance on the server which serves up bone standard HTML pages with a bit of javascript to glue them together. The advantages of this are obvious, the resulting pages are tiny and lightning fast to serve up and since there are no dependencies, setup is a breeze, there are never any runtime bugs, and you never have to apply patches or upgrades to the underlying engine. The downside is I need to write a template engine for swift which is a bit of a bear... or do I?.

Javascript has much better support built in and available as external libraries and I'm intimately familiar with the templating engine built into Underscore.js (actually I use Lowdash, but that's a minor detail); since iOS has great support for running javascript, it seems like a natural fit. I'm sure I'll run into some issues with this approach eventually, but for the moment my plan is to use Underscore templates (or for that matter, make it plugable so I can change template engines if I want).

Which brings up the 'final' initial choice here which is "How do I store the data?". On iOS, the obvious answer is CoreData or perhaps SQLLite, but I think I'm going to go with an old school solution here as well. A basic blog has a fairly small number of text based entries. If I store the pages as individual json files on the file system, it simplifies the system in a lot of ways. Since JSON is javascript, the files are easy to pass back and forth between the blogging app and whatever javascript rendering engine I decide to use. The only time the app needs to parse the file is when loading and saving the file and even then the boilerplate to do so isn't significantly more complex than pulling data in and out of CoreData. The JSON files can be stored in a way that turns them into a static REST API, which means the uploaded files can be consumed by other web services or utilized by javascript to make the resulting pages more dynamic. Finally, static text files are extremely easy to back up and troubleshoot.

So there you have it, I'm building a blogging app in Swift (Oops, I didn't mention that above I guess), which will upload static HTML files to a web host for you. It's going to use a javascript template engine and eat JSON files so I don't have to re-invent the wheel here. And finally "doubling down on meta" €”if you are reading this post, it's because my blogging app posted my blog about blogging about creating a blogging application so I can blog. It's gonna be great!