Added comments section to posts

2026-07-04 14:01

It's a rainy day today so I got my geek on. I can now add a comment box at the bottom of my posts. Comment sections aren't for everyone, but either are like-buttons, flickering GIFs, or pineapple. I personally just ebb and flow out of how or if I respond to posts, be it an email, reply post, mastodon comment, BBS response, or carving words into a pig. ahem.

My commentblock method doubles down on my existing Supabase database that hosts my text-wall (guestbook). It just adds a row to the two-column database for each post ("id" being the timestamp of the post, and "content" which is the dynamic text field containing the comments).

What you see is the same concept - a plain ol text box that you freely type into. No buttons, no nothing. Just type and it saves. About as loose as it can be. Luckily I have responsible adults reading my website who would never ever delete someone's comments, or worse, change their comments to make them sound like a dick. Right? RIGHT?! Just don't sign your name if you are a paranoid android.

Anyway, it is totally hackable if you are inclined to look at the source code and use my API key, but I trust you have better things to do. It does use javascript, so if you have that turned off you won't see a thing.

This is the janky python script I made which (1) adds a new row to the database corresponding to the date of the post, (2) creates a Codeberg page which is the actual html that you see in the commentblock, and (3) update the blog post to embed said html. See my Creating a text-wall post on how to set up Supabase.

import os
import re
from git import Repo
from supabase import create_client, Client

# Define ID from post date in post.md file.

post_md = '/home/zkbro/02-Areas/repos/zkbro-ws_v2/content/posts/POST-SLUG.md'
pattern = re.compile(r"date = ")
date_replacements = str.maketrans({"-":""," ":"",":":""})
with open (post_md,'rt') as file:
    for line in file:
        if pattern.search(line) is not None:
            post_id = line.rstrip('\n')[-19:].translate(date_replacements)
            break

# Connect to supabase database

url = "SUPABASE_URL"
key = "SUPABASE_ANON_KEY"
supabase: Client = create_client(url, key)

# Insert new row

print("Creating new row ID: ",post_id)

response = (
  supabase.table("text_wall")
  .insert({"id": post_id, "content": ""})
  .execute()
)

print("Row created.")

# Create corresponding Codeberg page

# Define codeberg repo directory

repo_dir = '/home/zkbro/02-Areas/repos/text-wall/'
repo = Repo(repo_dir)

# Copy a js_page_template to a html with post_id as the filename

post_id_dest = f'{repo_dir}{post_id}.html'
os.system(f'cp "{repo_dir}comment_page_template.html" "{post_id_dest}"')
print(f"Template copied to {repo_dir}{post_id}.html")

# Update the post_id variable in post_id.html with post_id

placeholder = "$POST_ID_PLACEHOLDER"
with open (post_id_dest,'r') as file:
    data = file.read()
    data = data.replace(placeholder, post_id)
with open (post_id_dest, 'w') as file:
    file.write(data)
print("post_id variable updated.")

# Add, commit, push to repo

origin = repo.remote(name='origin')
branch = repo.heads['pages']
branch.checkout()
repo.index.add([f'{post_id}.html'])
repo.index.commit('New comment page added')
print('Commited successfully')
origin.push()
print('Pushed changes to origin')

# Update post.md with embeded html

comment_block = f"""
---
## Comments

<embed type="text/html" src="https://zkbro.codeberg.page/text-wall/{post_id}.html" width="100%">
"""

with open (post_md,'a') as file:
    file.write(comment_block)
print("Comment block added to post")

Comments