Created: 2023-06-11
I've spent today and a bit of yesterday giving tayacan.dk an overhaul. Part of what I wanted out of it was a new, less boring design, and part of it was to try out the suite of web-related libraries that I want to use with my students in the coming school year. In this post I'll go over the setup I ended up with.
The site was previously hosted on GitHub pages, but for the new version I wanted to make it dynamic, so I've bought a cheap VPS and set it up there. Specifically, I am using SSDVPS, which is located in Denmark, and will cost me 408DKK per year. I've used their service before at work, and had no issues, so I'll go with them again for now.
The website is written in Python3, using the excellent lightweight framework Sanic. I like Sanic, because it has very few opinions on how my code should be structured. Essentially, you write functions that take an http-request as input, and return an http-response, and you can do whatever you want in between.
For generating the HTML, I use Jinja, which is the default template system for Flask, but which can also be used outside of that context. All pages on this site are written as Jinja templates, that are then populated with values from a Python dictionary.
Finally, for these blog posts, I use a folder full of markdown files, which are parsed with the Python-Markdown library. I use the built-in Meta extension for adding metadata such as a title, date, and optionally a header image.
I could have chosen to use Flask instead of Sanic, and gotten the Jinja templates integrated by default. I also could have used a larger framework like Django. But I wanted modularity, both because I find it easier to work with a bunch of small, specialized components that I understand well, and because I find such a system easier to teach -- you can teach each component individually, instead of needing to deal with the whole tech stack at once.
You'll also note that I haven't mentioned a database. There's nothing on the site that would particularly benefit from it, and so I have simply chosen not to use one. None of the libraries mentioned above assume that I will use one.
All in all, I find this modular approach both pleasant and straightforward. At present, the Python code sits at just under 80 lines, which I think is pretty good for a website with a blog! Of course, some of the logic lives in the template files, but that comes down to a couple of for-loops.