Skip to content
3 min read

How I Built blog.packbier.dev

Why this blog runs as a static SvelteKit site on Cloudflare Workers, how the Markdown build pipeline works, and how GitHub Discussions power comments for free.

On this page (4)

When I set out to build blog.packbier.dev, I had three constraints: zero hosting cost, clean SEO and link previews when sharing posts, and a writing workflow based purely on Markdown files in Git.

My first idea was a client-side frontend fetching static JSON from a GitHub repo. It works technically, but it introduces request waterfalls and breaks OpenGraph previews on platforms like Discord, LinkedIn, and Slack because their crawlers do not execute client-side JavaScript. Pre-rendering everything to static HTML at build time solves all of that with less code.

From Markdown to Static HTML#

Every post lives in its own folder under content/posts/<slug>/index.md together with any local images or diagrams. At build time, SvelteKit's static adapter crawls the site and outputs plain HTML pages, hashed static assets, /sitemap.xml, /rss.xml, and a lightweight /search-index.json for client-side search.

Static blog pipeline from Markdown to Cloudflare Workers
Build-time static pipeline with Cloudflare edge delivery and Giscus comments.

The build flow stays straightforward from commit to edge cache:

text
flowchart LR
  MD["index.md + images"] --> SK["SvelteKit Build"]
  SK --> HTML["Pre-rendered HTML + OG Tags"]
  SK --> RSS["/rss.xml & /sitemap.xml"]
  HTML --> CF["Cloudflare Workers Static Assets"]
  CF --> Reader["Browser + Giscus Discussions"]

The Markdown Pipeline#

Rather than shipping a Markdown parser or syntax highlighter to the browser, all content processing happens once during the build using unified, remark, and rehype.

Code blocks are highlighted at build time with Shiki using dual light and dark themes, while raw HTML passthrough stays disabled (allowDangerousHtml: false) to keep rendering predictable and safe:

src/lib/server/markdown.ts
export async function renderMarkdown(body: string) {
  const highlighter = await getHighlighter();
  const processor = unified()
    .use(remarkParse)
    .use(remarkGfm)
    .use(remarkMath)
    .use(remarkRehype, { allowDangerousHtml: false });

  return processor.process(body);
}

Mathematical notation is compiled at build time with KaTeX as well, so inline expressions like H(X)=−∑ip(xi)log⁡2p(xi)H(X) = -\sum_{i} p(x_i)\log_2 p(x_i) or display formulas render without any client-side script:

Speedup(s)=1(1−p)+ps\text{Speedup}(s) = \frac{1}{(1 - p) + \frac{p}{s}}

Comments and Reactions with Zero Backend#

Running comments usually means maintaining a database, authentication, and spam moderation. To avoid all of that, this site uses Giscus, which maps each post to a GitHub Discussion and gives readers GitHub-authenticated comments and emoji reactions out of the box.

Because Giscus requires a public repository, the setup uses a small split: the blog source and drafts stay in a private repository deployed to Cloudflare, while Giscus points to a separate public packbier/blog-comments repository that holds only Discussions.

Stack Overview#

Part Choice Why
Framework SvelteKit + adapter-static Pre-rendered HTML, clean routing, fast builds
Hosting Cloudflare Workers (Static Assets) Free tier, global edge CDN, custom headers
Code Highlighting Shiki (build-time) Zero client JS, dual light/dark themes
Math & Diagrams KaTeX + lazy Mermaid Static equations, theme-aware diagrams
Comments Giscus + GitHub Discussions Reactions and threads with no backend

If you have thoughts on this setup or spot something I could improve, feel free to leave a reaction or comment below.

Discussion & Reactions

Comments and emoji reactions are powered by GitHub Discussions via Giscus in packbier/blog-comments.