The comments fiasco
2026-07-05 17:12
Ok so the commentbox works pretty well. I saw 10-15!! comments before I went to bed (thanks Brennan, Chris, Steve, JP and all the other anonymous netizens - seriously I had no idea so many people were reading this thing). But, low and behold, some smart-Alec decided to delete the lot, either on purpose or by accident. I guess I kinda dangled the carrot, so I can't complain. Actually I imagined some kind of Butthead character snickering as they pressed the big red button. It is harmless fun, and a couple of you anticipated it in your comments. You can have a cookie.
Anyway, it rained again today. I don't really need an excuse, but I grabbed it anyway and did some shoddy coding again. I wanted to mitigate the Buttheads, I even drew little diagrams on paper, and eventually came up with a solution. It's brittle, but it'll do.
Since I don't pay for Supabase (where the database is hosted), I can't rollback and simply restore the lost data. I believe there's a self-hosted solution, but that's a big undertaking for this wee little project that may not stick. What I can do though, is pull the data itermittently via their API and capture the comments into a local CSV.
Because it is just one giant field of text, I have split comments using two new lines (\n\n) as the delimiter, which I've observed as what everyone was doing without any direction - a bit like a desire-line for how you separate your comments in freetext. A table of 5 comments now looks like this:
$ cat 20260704140152-master.csv
,entries
0,hi
1,This is pretty neat! --Steve
2,"Ok, messages are being lost.. I have an idea."
3,Sweet
4,Yo
I didn't stop there though. No point in me just hoarding the comments all for myself. How about I throw them back onto the post page scattered around the background? So I did that too:

One of the comments triggered this idea for me, thanks stranger! It was something about an old pinboard, and that there were always jerks who would pull off the notes. Except now the comments are pinned and you can't take them down. HA!
I love this look. Hopefully they don't pop out too much to disturb the reading. Ii think I've made them faint enough.
Here's the code that pulls the data into tables, updates any new entries, and spits them back into the post toml frontmatter:
import frontmatter
from frontmatter.default_handlers import TOMLHandler
import pandas as pd
from pathlib import Path
from supabase import create_client, Client
from datetime import datetime
import pytz
post_filename = 'added-comments-section-to-posts.md'
# Connect to supabase database
url = "SUPABASE_URL"
key = "SUPABASE_ANON_KEY"
supabase: Client = create_client(url, key)
# Fetch data
response = (
supabase.table("text_wall")
.select("content","id")
.eq("post_filename", post_filename)
.execute()
)
post_id = response.data[0]['id']
s = response.data[0]['content']
# Split into individual items and parse to list
split_entries = s.split('\n\n') # seems the most practical
# Create df
df = pd.DataFrame(split_entries, columns=["entries"])
# Save to CSV
# Save master if it doesn't exist
tz = pytz.timezone('Pacific/Auckland')
ct = datetime.now(tz).strftime("%Y%m%d%H%M%S")
master_file = Path(f'{post_id}-master.csv')
new_file = Path(f'{post_id}-{ct}.csv')
if master_file.exists():
df.to_csv(new_file)
else:
df.to_csv(master_file)
# Compare to existing CSV and append new entries
master = pd.read_csv(master_file, index_col=0)
new = pd.read_csv(new_file, index_col=0)
new_entries = new[~new["entries"].isin(master["entries"])]
master = pd.concat([master, new_entries], ignore_index=True)
print(master)
master.to_csv(master_file, index=True)
# Add comments to post background
post_file = Path(f'/home/zkbro/02-Areas/repos/zkbro-ws_v2/content/posts/{post_filename}')
master = pd.read_csv(master_file, index_col=0)
entries = master['entries'].tolist()
post = frontmatter.load(post_file, handler=TOMLHandler())
extra = post.metadata.setdefault("extra", {})
extra["comments"] = post_id
extra["commentz"] = entries
with open(post_file, "w") as f:
frontmatter.dump(post, f)
I probably need some kind of cron job do this regularly. For now, I'll just do it every-so-often, which means I may miss some entries if the Butthead gang is heavily active.
python-frontmatter was a new library to me. I started doing straight up text replacement, but stopped because it was doing my head in. Did a quick search and found this one which proved to be so much quicker.
Just having the comments in the frontmatter doesn't do anything until I tell my Static Site Generator Zola to do something with it. I had previously done some nifty things with the get_random function which I now use here to "throw" the comment somewhere randomly onto the page:
{% if page.extra.comments %}
{% for comment in page.extra.commentz %}
<div class="bg_comments" style="top: %; left: %; transform: rotate(deg);">{{ comment }}</div>
{% endfor %}
{% endif %}
CSS:
.bg_comments {
position: absolute;
overflow: hidden;
z-index: -1;
background-color: var(--comment-bg-color);
color: var(--comment-color);
padding: 5px;
}
I'm doing something wrong with the top: 1-100% and overflow: hidden styling as it still seems crowded at the top screen height, rather than the full post height. I'm not done with this yet.