<- back
view in plain-text
2020-05-27

Site changes

New stuff at the {back,front}end

The past couple of days, I’ve spent a fair amount of time tweaking this site. My site’s build process involves vite and a bunch of scripts. These scripts are executed via vite’s pre- and post-build actions. The big changes that were made were performance improvements in the update_index.py script, and the addition of openring.py, which you can see at the very bottom of this post!

speeding up index page generation

The old script—the one that featured in Hacky scripts—was absolutely ridiculous, and not to mention super slow. Here’s what it did:

  • got the most recent file (latest post) by sorting all posts by mtime.
  • parsed the markdown frontmatter and created a markdown table entry like:
line = f"| [{meta['title']}]({url}) | `{meta['date']}` |"
  • updated the markdown table (in _index.md) by in-place editing the markdown, with the line created earlier—for the latest post.
  • finally, I’d have to rebuild the entire site since this markdown hackery would happen at the very end of the build, i.e, didn’t actually get rendered itself.

That…probably didn’t make much sense to you, did it? Don’t bother. I don’t know what I was thinking when I wrote that mess. So with how it was done aside, here’s how it’s done now:

  • the metadata for all posts are nicely fetched and sorted using python-frontmatter.
  • the metadata list is fed into Jinja for use in templating, and is rendered very nicely using a simple for expression:
{% for p in posts %}
  <tr>
    <td align="left"><a href="/blog/{{ p.url }}">{{ p.title }}</a></td>
    <td align="right">{{ p.date }}</td>
  </tr>
{% endfor %}

A neat thing I learnt while working with Jinja, is you can use DebugUndefined in your jinja2.Environment definition to ignore uninitialized template variables. Jinja’s default behaviour is to remove all uninitialized variables from the template output. So for instance, if you had:

<body>
    {{ body }}
</body>

<footer>
    {{ footer }}
</footer>

And only {{ body }} was initialized in your template.render(body=body), the output you get would be:

<body>
    Hey there!
</body>
<footer>

</footer>

This is annoying if you’re attempting to generate your template across multiple stages, as I was. Now, I initialize my Jinja environment like so:

from jinja2 import DebugUndefined

env = jinja2.Environment(loader=template_loader,undefined=DebugUndefined)

I use the same trick for openring.py too. Speaking of…let’s talk about openring.py!

the new webring thing at the bottom

After having seen Drew’s openring, my NIH kicked in and I wrote openring.py. It pretty much does the exact same thing, except it’s a little more composable with vite. Currently, it reads a random sample of 3 feeds from a list of feeds provided in a feeds.txt file, and updates the webring with those posts. Like a feed-bingo of sorts. ;)

I really like how it turned out—especially the fact that I got my CSS grid correct in the first try!

Questions or comments? Send an email to ~icyphox/x@lists.sr.ht—my public inbox.


How To Track Desert Locust Swarms

Billions of desert locusts are swarming across East Africa, multiplying in numbers over several months of favorable rain and breeding conditions, creating what the UN Food and Agriculture Organization (FAO) called an “unprecedented threat to food security,…

via bellingcat on Jun 23, 2020

OpenBSD on the Microsoft Surface Go 2 (notaweblog)

I used OpenBSD on the original Surface Go back in 2018 and many things worked with the big exception of the internal Atheros WiFi. This meant I had to keep it tethered to a USB-C dock for Ethernet or use a small USB-A WiFi dongle plugged into a less-than-…

via joshua stein on May 15, 2020

25/05/2020: This month in KISS (#2)

Welcome to the second monthly update for KISS. This post will be quite a long one, we've seen some nice changes this month and some great work by the Community.…

via KISS Linux Blog on May 25, 2020

Generated by openring.py

email
x@icyphox.sh

github
icyphox

mastodon
@x@icyphox.sh

pgp
0x8A93F96F78C5D4C4

last updated
76b554e on 2020-06-24

friends

Some of my friends and internet bros.

about

More about me and my work.