Earlier this year, I had an idea to automate the Sample Programs website. Turns out, it wasn’t that hard to do. Now, the website is automatically built on every pull request. Let’s talk about it!
Table of Contents
What Is Website Automation?
Previously, the Sample Programs website was only partially automated. Basically, all articles were written by hand and had to be updated by hand. That said, the website itself was built automatically using GitHub pages.
One thing I wanted to do was loop in Subete, so we could generate a majority of the website by traversing the repo. In other words, we could build out all of the Sample Programs pages automatically. Not only that, but we could also build out the major index pages automatically.
As a result, we have a website where all of the articles are automated based on Subete. The majority of the documentation still needs to be written by hand, but the code itself exists as expected. In other words, here are pages that are fully automated:
In addition, all subpages are fully automated. For instance, the Python language page is built dynamically by pulling in existing docs. Likewise, the Fizz Buzz in Python page is generated in a similar capacity. In the next section, we’ll talk about how this was done.
How to Automate a Website?
As mentioned previously, a major driver of the automation was a tool I developed called Subete. In short, Subete is a library for exploring the Sample Programs repo. As a result, you’ll get Python objects that represent the repositories contents.
In addition, each page is automated using another library I wrote called SnakeMD. SnakeMD is a tool for generating Markdown code using Python.
Together, the two libraries are used to iterate over the Sample Programs repo while simultaneously generating the appropriate Markdown for the website. The code itself is pretty messy, but it helped me flesh out some real world use cases for both of my libraries. As a result, they’re significantly more robust.
With all that said, the final task was to link in existing documentation, so I changed up the repo’s structure. Now, all sources can be found in the sources folder. If the sources exist at the time of website automation, they’re looped in. Otherwise, generic text is included.
Ultimately, everything is hooked into GitHub Actions which regularly generate the website on each push to main. How cool is that?
Looking at the website as it stands, there are definitely some issues I’d like to resolve. For example, the actual sample programs pages are a mess. They include the current solution but old documentation still sits around. Therefore, there’s a mismatch. Likewise, each sample program page includes a “how to run the solution” section which is fairly redundant at this point. It should be automated.
With that said, I’m not planning to work on the website for a while. I like where it’s at, and I’m busy otherwise. If anyone would like to take this project on, let me know!
While you’re here, why not check out some more cool stuff:
- The Great Subdomain Purge: Sample Programs Has a New Home
- The Sample Programs READMEs Now Feature Missing Solutions
- Practice Your Coding Skills With the Sample Programs Template
Likewise, if you’re interested, consider supporting the site in other ways. Otherwise, take care!
Recent Meta Posts
Life has given me a bit of a beating, so I'm taking some time to recover. See y'all again soon.
2022 was a weird year as we transitioned out of the pandemic (though, I did get COVID). In it, I managed to turn 28, pass my candidacy exam, and travel to see my friends and family. Who knows what...