Building a Micro-Post Publishing Station for My Blog

This article is currently an experimental machine translation and may contain errors. If anything is unclear, please refer to original Chinese version. I am continuously working to improve the translation.

This project was almost entirely completed by GLM 5.3 Flash, and the first draft of this article was also written by it. Although the writing has been manually polished, many parts still lack a human touch). Well, so be it. This model's capabilities are pretty trash anyway — if it weren't for the free tokens, I wouldn't use it.

Origin: Moments Existed, but Publishing Was Too Painful

I previously added a moments feature to my blog — an information waterfall for quick jottings — but at the time I didn't bother with how to publish to it afterward. It remained the very primitive form of hand-editing YAML files, where even aligning the format was a bit of torture.

So the goal this time was clear: build a web-based publishing station that works on both phone and computer — write something, click publish, images automatically go to the image host, and the YAML gets committed automatically.

First Round of Solution Design

Plan before building. The core architecture had to fit into the blog's existing deployment workflow: the blog is purely static — push to main → GitHub Actions builds → gh-pages → served on both GitHub Pages and Cloudflare Pages.

So the essence of the publishing station could only be: collect images into the image host, commit a new record into moments.yml, and let the existing CI rebuild automatically.

Through Q&A with the Agent, three decisions were settled:

  1. Authentication: the publishing station must be usable only by me. Chose Cloudflare Access + GitHub login (Cloudflare Zero Trust, more on this later).
  2. Feature scope: publish + edit + delete, all in one go.
  3. Image host: images go directly into my existing R2 bucket image.wendaining.top, served publicly via its custom domain.

Two implementation details as well:

  • Deferred image upload: images selected, pasted, or dragged in are only held in browser memory — you can freely add, remove, and reorder them — and they're only compressed and uploaded when you click "Publish". Abandoning midway leaves no garbage in R2.
  • Date locking: when editing an existing moment, the date field is read-only, mainly because a single moment's permalink is bound to its date.

Recon Before Starting

First I took stock of what I had on hand; a few findings directly shaped what came next:

  • The local gh CLI was already logged in with my account, and the token had repo + workflow permissions. This meant most GitHub-side operations (creating repos, storing secrets, pushing workflows) could be done directly by the AI on my behalf.
    • Here the Agent said a Fine-Grained PAT was needed, but I found that too much hassle and said the gh cli token would do, so I just used it — though this apparently carries an expiration risk.
    • (Also, I honestly wasn't quite sure what this Token was for. When I asked the LLM, I got a TLDR-style answer: "Your token is essentially 'giving the AI a key to your GitHub operations'; repo + workflow means this key can modify code repositories and GitHub Actions, and a Fine-Grained PAT just cuts this key into finer pieces." Okay then.)
  • The Agent had the official Cloudflare plugin installed, so the agent could directly operate my Cloudflare account.

Pitfall One: Agent's Tool List Failed to Load Dynamically

During the planning phase I asked the AI: can the Cloudflare account management MCP be used? Its judgment at the time was "my tool list only has documentation retrieval; the account management tools aren't mounted," and then it started frantically searching documentation to back up that conclusion.

This was genuinely mysterious. In principle, an Agent's Tool List is loaded dynamically as the conversation progresses, and I don't have many MCPs — loading all of them is entirely feasible. This could only be a bug. I restarted, and everything showed up.

Cloudflare One Explained

This explanation was written by the LLM; it's basically a translation of Cloudflare's official documentation (?), plus some analysis.

Cloudflare One is the umbrella name for Cloudflare's enterprise security product suite — the marketing name is "Zero Trust SASE." Broken down, it's three things:

  • Zero Trust: "zero trust" is a security model — no longer assuming "things inside the intranet are trustworthy," but instead verifying identity and permissions for every access request, no matter where it comes from.
  • Access: the most commonly used feature in the zero trust model, essentially an authentication checkpoint standing in front of your application (the technical term is Identity-Aware Proxy). Visitors are first intercepted to log in; only if their login info matches the policy are they let through to the application behind — otherwise they can't even see what your server looks like.
  • Organization: the Zero Trust entity under your account, with a globally unique team domain (of the form xxx.cloudflareaccess.com); all login redirects go through this domain.

For a personal blog, the free tier of this suite is more than enough. The effect: wrapping the publishing station in a shell of "only I can open it," without writing a single line of authentication code yourself.

The actual order of operations is:

  1. Click "Enable Access" in the dashboard and choose the free plan (no card required). This step automatically creates the organization and assigns a team domain — **mine was randomly generated by Cloudflare as wild-rice-7d8e.cloudflareaccess.com, though it can be changed later, so no big deal.
  2. Add an Identity Provider (login method): tell Access "what to log in with." If you choose GitHub, you need to create an OAuth App on GitHub yourself (get the Client ID and Secret and fill them into Access), and set the OAuth App's callback URL to https://你的团队域/cdn-cgi/access/callback.
  3. Create a self-hosted Access application: declare "this domain/path is protected," and attach policies to the application.
  4. Policy: rules of the form "Allow + some condition." My configuration is an exact email match against my own GitHub primary email; there's also a non_identity decision type, specifically for Service Tokens — programmatic access that doesn't go through browser login, exchanging a Client ID + Secret for a JWT. The E2E tests relied entirely on this.

How Workers Bind Resources

First, an explanation of how a Worker's JS code is generally uploaded:

  1. Upload via Wrangler
  2. Upload via the API provided by the Cloudflare MCP

Either way, it's just submitted — it's not tied to a Git repository or anything like that.

Also, a note on Cloudflare Worker bindings:

A Worker itself is a piece of JS running on Cloudflare's edge; a binding "attaches" an external resource into its runtime environment so the code can use it directly as a variable:

  • r2_bucket binding: in code, a single line env.IMAGES.put(key, bytes) writes into the R2 bucket — no S3 keys to configure, no signing.
  • secret_text binding: encrypted environment variables, for storing sensitive values like GitHub tokens.
  • plain_text binding: ordinary configuration (image host domain, blog address, and the like).

This deployment didn't use wrangler; it went entirely through the REST API, in three steps:

  1. POST /accounts/{id}/workers/workers: create the Worker resource (no code yet at this point).
  2. POST .../workers/{id}/versions: upload a version, containing the code modules (base64) and all bindings.
  3. POST .../scripts/{name}/deployments: point 100% of traffic to this version.

One more thing: PUT /accounts/{id}/workers/domains binds moments.wendain.ing as the Worker's custom domain (DNS and certificate configured automatically); and the workers.dev preview entry is turned off, so the publishing station has only the one Access-protected door (moments.wendain.ing).

Pitfall Two: The LLM Tried to Base64-Encode Directly

This one was baffling. I didn't follow the process, but after it finished I roughly understood what had happened:

As mentioned in the previous step, we need to upload JS code to the Worker via an HTTP POST request. But how does that HTTP request carry the JS file?

The reasonable approach would be to put it directly in the POST request's content:, but some of the Cloudflare Workers API's upload endpoints actually require the source code content to be base64-encoded. So the original JS code was base64-encoded and sent up.

But this model was absolutely unhinged — it performed the Base64 encoding using thinking rather than a tool call, and the result was a pile of garbage that kept reporting malformed base64 content.

The final solution:

  1. Embed the original source code in the tool call (readable, inspectable — not base64 ciphertext);
  2. Let the Cloudflare sandbox encode it to base64 on the fly during execution;
  3. The sandbox conveniently returns the SHA-256 of each file, which is compared locally — only continue if everything matches; if not, resend the mismatched files.

This "hash verification loop" saved me more than once later on. Including when rewriting the generator script, I hit another shell-escaping pitfall: writing \n inside bash double quotes turned into a real newline when passed to Node, breaking the generated code string outright. The fix was to write the generator itself as a file and execute it, completely bypassing shell-escaping hell.

E2E: All Green in One Pass

After deployment, I ran a full end-to-end test: create a temporary service token → upload a 1×1 PNG → confirm it's served correctly from the image host domain → publish a test moment → edit it (confirming the ID stays the same) → delete it (confirming the R2 object is cleaned up in sync) → delete the token.

Along the way I discovered that the Cloudflare sandbox's outbound fetch has a whitelist and couldn't reach my publishing station's domain, but local curl went straight through — HTTP 200 — so the entire E2E was run locally.

"Where Are the Frontend Files?" Unhinged GLM 5.3 Flash

662

This was simply unhinged. After it finished running, I looked at the project and it was all JS code. I asked, got this reply, and honestly lost it.

To be lazy, the LLM had inlined the entire interface (HTML + CSS + JS) into one giant template string inside src/ui.js. So I had it refactor, splitting things into HTML, CSS, and JS.

Midway through the refactor, an even more insidious bug surfaced: the public/ rule in the repo root's .gitignore (originally meant to ignore Hexo build output) was also silently ignoring moments-composer/public/ — git add simply wouldn't include it, and the commit almost ended up without the frontend files. The fix was anchoring the rule to the root directory as /public/.

Interlude: Should It Move Under the Blog's Domain?

Along the way, another approach was discussed: drop the separate subdomain and mount the publishing station under the blog.wendain.ing/moments-composer path, making it look like a sub-app of the blog. The feasibility conclusion was that it's doable — Workers routes can be attached by path to a Pages custom domain, and the Worker takes precedence over static serving — but it would require reworking the Worker's path handling and rebuilding a path-level Access application. In the end I decided to shelve it: the existing separate subdomain was already working stably, and there was no need to churn things up just for aesthetics. This approach can always be done separately later.

submodule: Making the Publishing Station Its Own Repo

I split moments-composer/ out of the blog repository into a git submodule pointing to the standalone private repo wendaining/moments-composer. Mainly because the composer is a self-contained application, and mixing its commit history in with blog content commits is weird. Once it became its own repo, the blog repository only keeps a pointer.

A few key moves:

  • git subtree split -P moments-composer: extract the composer-related commit history from the blog repository and push it as the new repo's main — no history lost.
  • Switch the blog side to a gitlink: git rm -r the old directory, git submodule add the new repo. The Hexo build doesn't depend on this directory at all, so the blog's CI needed zero changes.
  • Redeploy the Worker: the repo structure changed, so the code running in production had to be aligned with the new repo. Same "embed source + sandbox encoding + SHA-256 comparison" flow as before — this time all eight files passed in one go.

Pitfalls hit in this stretch:

  • Pitfall: the root .gitignore's public/ silently ignoring things. The one mentioned above — git add throws no error and gives no warning; the files just aren't in the commit. I only discovered this after rm -rf, and had to rebuild them from memory.
    • Lesson: when writing ignore rules for nested directories, always anchor to the root with /.
  • Pitfall: rebase blocked by the submodule. The remote had new commits I'd pushed from another machine; during the rebase, git needed to switch moments-composer/ from "submodule" back to "regular file directory," but was blocked by the already-populated submodule working tree, throwing a baffling "cannot detach HEAD" error. The fix was git submodule deinit to clear it out, then --init to restore after the rebase.
  • Pitfall: detached HEAD. When git submodule update --init restored the submodule, it was in a detached HEAD state by convention. The two commits I made afterward all landed on the detached head, and git push origin main pushed the old branch — the push showed success, but in reality nothing was pushed. I only realized what happened when I noticed the remote tree had no .github directory at all. The fix was git checkout -B main to bend the branch back.

The Last Puzzle Piece: Automatic Submodule Alignment

Submodules have a problem (maintenance cost): after the composer repo updates, the pointer in the blog doesn't move by itself — you need to manually run git submodule update --remote and commit again.

The first version of the plan was CI on both sides: a workflow on the blog side to check and align the pointer, and the composer side notifying it after a push. Once running, it turned out the blog-side one was redundant — and it also hit credential problems when its internal git submodule update --remote cloned the private sub-repo (the checkout's credential header didn't cover the submodule clone), failing repeatedly.

Following the principle of "less is more," I deleted the blog-side workflow entirely and changed the composer-side workflow to do it itself: via the Git Trees API, directly commit the blog's gitlink as the new SHA — no need to clone the blog, no need to touch the submodule. Three API calls (read the current pointer → create a new tree and commit → PATCH the ref) complete the alignment, idempotent with automatic retries on failure.

Another pitfall along the way: writing a heredoc in the workflow's YAML, the terminator EOF got dragged out of column zero by the YAML indentation, and the shell directly reported here-document delimited by end-of-file. Switching to a printf | gh api --input pipe approach made the problem disappear.

Tested result: push one commit to composer, and a few seconds later a chore(composer): sync submodule to xxx automatically appears on the blog's main — pointer synced. From now on I only need to care about the composer repo itself; the blog needs no attention at all.

Wrapping Up

The final form of this whole setup:

  • moments-composer: a standalone private repo — the frontend trio + five Worker backend modules + deployment scripts, with tests included.
  • One Cloudflare Worker in production, protected by Access (GitHub login), accepting only my GitHub email; images land in R2, served via the dedicated image host domain.
  • A submodule pointer in the blog, kept up to date automatically by the composer-side CI.
  • Not a single line changed on the Hexo side — validation, IDs, permalinks, Giscus are all the original system.

Building a Micro-Post Publishing Station for My Blog
https://blog.wendain.ing/en/posts/moments-composer-build-log/
Author
wendaining
Posted on
September 6, 2026
Licensed under