Skip to content
YuHaibo
Go back

Adding a Comment System to Astro Blog with Bluesky

Table of contents

Open Table of contents

Overview

This post documents how to build an automated comment system for a static blog using the Bluesky API. The workflow is simple: every new post automatically creates a discussion thread on Bluesky, and comments are rendered asynchronously on the blog page.

Publishing Pipeline

To ensure social platforms can correctly scrap preview cards (Open Graph), the publishing process must follow a strict sequence. I implemented this using GitHub Actions:

Core Workflow

  1. Build and Deploy: Code is pushed to main, built by GitHub Actions, and deployed to Cloudflare Pages.
  2. Deployment Verification: A script polls the new article URL. It waits until the page returns HTTP 200 and contains valid og:title and og:image tags.
  3. Auto-Post: Once verified, the script calls the Bluesky API to create a post, manually constructing an external embed object with a thumbnail to ensure a high-quality link card.
  4. Update Mapping: The script retrieves the post uri and url from the API and saves them to src/data/bluesky-comments.json.
  5. Second Deployment: The Action commits the JSON change. This triggers a second deployment (which skips the post step because of the existing record), making the comment ID available on the production site.

Guardrails

Comment Embedding

Data Fetching

Instead of Server-Side Rendering (SSR), comments are loaded via client-side JavaScript to keep the site performance-friendly:

  1. Locate Resources: The component reads the global mapping JSON to find the Bluesky post uri for the current page.
  2. API Call: It uses the browser fetch to request the public Bluesky getPostThread endpoint.
  3. Data Transformation: The raw thread is flattened to extract avatars, author names, content, and engagement counts (likes/reposts).

Rendering Strategy

Why This Solution?


Share this post on:
Loading comments...

Next Post
eSIM Best Practices