At the moment, my favourite language is Python. It just clicks for me, and it feels like a nice multi-tool of server side languages that ticks most of the boxes I need, so as I can achieve success in the projects I want to pursue.
I quickly came up with an alternative: bash. I realised I could just do a 'curl' or a 'wget' to fetch data from an endpoint and then save it locally. Bingo!
So why bash instead? Well, I had been pinging the API endpoints from the command line using curl, and seeing as I was hosting my site with Netlify, I concluded that a bash script could run on a Netlify container as the base image was Ubuntu. So that's what I did, but it wasn't as elegant a solution as I wanted, mainly because:
- bash is great, but it wasn't what I was after to manipulate and transform the data after I had fetched it
- everytime I committed to git, it was a bit of a nuisance to change the script to be executable once added. It was only an extra line of code in the commit, but I still found ti awkward
- the added cumbersome nature of using bash just made me short of patience, because all the time I was wanting to make the site, I instead found that I was hacking at something that just was never going to deliver what I wanted
I'm happy that I know enough about bash and how to use it, for it to be useful in other projects, but this wasn't the project for me to use it on. So I banked that knowledge and moved on to my next language, Python, based on something a friend said to me - 'As soon as I started learning it, I didn't have to think about it.'
And the rest is history. I love Python. I found the 'requests' module and used that to hit the APIs I needed - job done. But then I could manipulate that data so easily, and transform it in to the shape I needed for my website. Following on from that, I could move some of the complex logic that I had been using within the Jekyll templates with the Liquid templating language, and let Python churn through that before offering it up to Jekyll to render a lot quicker. The things I like about Python are:
- If you've got Linux, you've got Python. I do not have to worry about installation.
- I do not need to make Python scripts executable. They will just run.
- Python can do anything! Everything I've needed to do - manipulating data, strings, file management, http requests - Python has been able to do it, and do it fast. I know there are plenty of people that will say other languages are quicker, which is true, but for what I need, Python will rip through anything I throw at it.
- Probably one of the most important things for me - I'm fast in Python. The syntax feels friendly and make sense to my brain, and so all I have to do to realise my goals is to just find the time and code the solution.
As I iterated over that project, I abandoned Jekyll completely, and wrote my own custom Static Site Generator that is specific to the task I had. That might sound like over engineering, but if you think about the fact that most Static Site Generators are designed to be configurable to serve so many differentt requirements, a custom solution can be much more lean and, for me at least, much faster. And Python is well placed to write such a tool with comparative ease.
No experience is wasted, and nothing lasts forever, so don't be afraid to try other things.