Jayant Godse

Making my own static site generator

Oct 29, 2026

I have had the great pleasure of travelling a good deal around the world. I also wanted some way to showcase the photo’s that I’ve taken during my travels. This want luckily coincided with a university subject that I was taking where I needed to make a software project in C++ that would demonstrate my ability to work with it.

Organising Code

I think one of the cooler constraints that I had on the project was the fact that it couldn’t be Object Oriented in design. All my training as a software engineer has made me instinctively think of systems in terms of objects. It’s a design choice that comes quite naturally. So it took a bit of time for me to first come up with a solution that focused more on the transfer of immutable structs rather than objects. Then to actually implement that without falling into my own habits. It was a nice thought exercise. I will say that it was quite fun going about implementing that.

Reading JPG Images

Wikipedia has a surprisingly well written article on the JPG format. I was able to pull most of the information that I needed to start reading images from just that page. Seeing as though I do not care for the entirety of the image, I only had to scan specific things in each JPG file that I read. Namely:

  1. I need to know if the file is a JPG
  2. I need to know where the metadata for the file starts

Both of these are simple enough tasks. To figure out if a file is a JPG, you have to look for 2 specific bytes. (0xFF and 0xD8). These 2 bytes denote the start of a JPG file.

After that I needed to look for an EXIFF tag. This is normally encoded as ASCII in in the file after the JPG headers are done. So you skip forward by a couple bytes and look for the start of the header:

> hexdump -C 'path/to/file.jpg' | head -n 5
00000000  ff d8 ff e1 2f 57 45 78  69 66 00 00 49 49 2a 00  |..../WExif..II*.|
00000010  08 00 00 00 0b 00 0f 01  02 00 07 00 00 00 92 00  |................|
00000020  00 00 10 01 02 00 08 00  00 00 99 00 00 00 12 01  |................|
00000030  03 00 01 00 00 00 01 00  00 00 1a 01 05 00 01 00  |................|
00000040  00 00 a1 00 00 00 1b 01  05 00 01 00 00 00 a9 00  |................|

Handling EXIFF data

EXIFF, in my understanding, is just a large dictionary of key value pairs that describe the contents of the image that you are looking at. As such all I need to do is firstly find the key that I’m interested in and then find the value that the key describes. For my very simple program here, I only need to find the ‘orientation’ tag. That is, I need to find 0x0112 which is easy enough. I had a little trouble figuring out how to do this with big vs little endian, but I took that time to finally learn how to actually do bit arithmetic in C++.

Turns out that in order to translate a number from little endian to something useful you just have to byte1 | byte2 << 8 so you can read 0x34 0x12 from the file, and convert that to 0x1234

Once I knew if the image had been rotated or not. I could then flip it back to its original rotation. This was a bit tedious to write out. But it’s just rotating a matrix, so nothing I haven’t done before. Then we were good to go.

Takeaways

Now I can’t say this is the most comprehensive Static Site generator. I’ve made a quite a lot of tradeoff in order to get it to work properly. For instance, it really only supports JPG’s getting uploaded. I’m not creating multiple sized versions of the image to show different clients and I’ve most likely got a bug somewhere in my code that I haven’t tested enough to have found out. It does what I want it to do. It lets me show off the places that I’ve been to. It lets me share this information without having it tied to some large corporations application. So I’m quite happy.

Praise for RFC’s

Throughout the process of figuring out how JPG images are encoded, I stumbled on the original RFC’s that describe the file formats and the decisions behind them. I will say, they are quite dry documents, but it was enlightening reading them nonetheless.

I was caught off guard by how approachable these documents are. Firstly, they are available quite easily. It takes scarcely any digging to find them. Secondly the language used, whilst technical, is not obtuse. Decisions are quite easily laid out and explained. I suppose it only makes sense, seeing as though they were all authored through consensus, but the tone is measured and insightful. I guess writing down technical decisions and opening them up to discussion is a good idea.