Three stacked blue boxes with binary digits on them
Bit flipping laboratory & Personal website
No sneaky cookies haunt these pages, but whether someone tracks you I do not know. Information flows through many channels, and every action leaves a trace.

2023-07-14
Story of this static website. Working with Pyramid and Mako templates. Hosting on GitHub Pages. Scripts for efficient development, serving locally, and remote deployment.

Making a personal website

American law asserts and usually honors the individual right of self expression. New England residents usually accept diversity in individuals. In my head, and especially in my past, the situation was very different. Some thoughts were wrong, many feelings were "inappropriate", and self-censorship was a way of life. In adulthood I eventually found social groups where people encourage deep communication and honesty. I found a meditation practice that welcomes every thought and feeling without filters and without judgement. Feelings come, feelings go.

In some ways, I benefited from being mostly silent. I learned to listen and understand people. I avoided unecessary conflict. In other ways, I missed the boat. Expressing myself could have helped me understand myself better sooner. It could have helped me form closer connections with more people sooner. A personal website is about public expression, which in my opinion is the least useful kind. My hope is not to use a website as a megaphone or to convince people of things. It's to help me explore and communicate a little more precisely than I can in my head or in conversation with friends, and I hope it will be helpful to others too.

It's so early 2000's, like when I first thought of doing this, except now it's HTML 5!

The vision

Here are some of my ideas. From there it's figuring out the best technology stack, and starting to make some things happen with my spare time.

One technology stack usually isn't universally better or worse than another. Good choices depend a lot on context: your skill set, what you're trying to accomplish, time constraints, and likely many other considerations. There are so many choices. The vision for me boils down to some kind of templating language with the full feature set of HTML, available, a dynamic web framework to run locally, and a free web hosting service. Additionally the hosting service needs to be able to run the webapp, or I find some utility to crawl the site and convert it into static content.

Mako templates

There are a lot of templating languages out there. The idea is you want reusable pieces of content that are easy to work with, instead of straght HTML. You also want to be able to make the content of some pages depend on external data, like when you are making an index of articles. I went with mako. Mako templates are little like PHP files in the sense you intermingle HTML with scripting, except that with Mako the scripting language is python. They also support templates that use an HTML-like notation. And you can nest your templates. I may come back and talk about the pros and cons of working with mako later.

I also considered hugo, which is a full static website builder that supports a mixture of Markdown and HTML. Markdown looks nicer than HTML for most things, and it's also less cumbersome to work with; but for complicated things the flexibility of HTML is just the only choice, and I'd rather work with one templating language than two. The main reason I decided against hugo though was I think the site structure it imposes would be too rigid for argument maps and interactive fiction. A quick search will reveal there are countless other choices for templating languages too.

Pyramid web framework

Like most things python, you can choose from way too many web frameworks. I don't know anything about any of them, but I chose pyramid because it claimed to readily support mako templates.

pip install pyramid pyramid_mako

The annotation-based configuration is a little annoying, but so far the framework is good enough. A project like this isn't sophisticated, and shouldn't stretch the limits any web framework very far.

I also considered using the mako library directly, and rolling my own build phase that produced HTML from the templates via a script. That worked, but the downside was it was inconvenient to run the script every time I wanted to see what a page looked like in the browser. The library was fairly easy to work with anyway.

GitHub Pages

I found that GitHub Pages provides free web hosting with a custom domain name. You can't host webapps though, only static content. Luckily wget can help convert a webapp into static content. There are some nuances to getting it set up. You create a special publishing repository, sbaldasty.github.io in my case, and tell GitHub that is your site. There can be more complicated workflows, which I didn't use.

To set up a custom domain name you need a CNAME file in the publishing repository root that contains the domain name. There are additional steps on the domain name side, like setting up A records. For the moment, I won't document those here since I am eager to get to work on other things.

This series of commands deploys the static website to GitHub Pages. The current directory should be where your Pages repository is checked out. If combining the commands into a single bash script, then configuring the script to terminate on errors is also nice. That way in case someting goes wrong with the static content generation, the actual deployment does not take place.

# Update in case site was deployed from another device
git pull

# Delete everything except the .git directory
find . -mindepth 1 -not -path './.git*' -delete

# Convert webapp to static content
wget --mirror \
  # Add .html extensions when needed
  --adjust-extension \
  # Recursively copy referenced resources
  --page-requisites \
  # Don't copy resources higher up the tree
  --no-parent \
  # Don't wrap the whole site in a subdirectory
  --no-host-directories \
  # Where to start from
  http://localhost:6543

# Restore CNAME for GitHub Pages
echo "bitflippin.com" > CNAME

# Deploy changes
git add .
git commit -m "sync static site"
git push

The idea is to delete all the content in the publishing repository locally except for the git metadata, and then use wget to reconstruct it from scratch. This should result in a nice clean diff to push, with the just latest changes. There's an extra step to restore the CNAME file, because I found restoring it easier than excluding it from being deleted in the first place.


Steven Baldasty
Proud father, Barefoot runner, Chocolate enthusiast, Seasoned software engineer, Starry eyed PhD student, Novice human
Handsome brown haired man with glasses