From Obsidian to Blog: One Container, One Plugin, One Night
This blog post explains how it came to be: a Hugo static site + receiving API + Caddy running in a Docker image on a NAS, plus an Obsidian plugin to push notes with one click. Architectural trade-offs, the reality of access in China, multilingual solutions, and three pitfalls encountered.
Requirements and Constraints
What I wanted was simple: finish writing in Obsidian, press a shortcut key, and the article is on the blog. No backend, no database, no third-party publishing platform; the only truth of the article is the local Markdown file.
There are three constraints: the domain is purchased from Cloudflare; the blog runs on a home NAS in Docker (NAS is overseas); friends in China must be able to access it. The third point has an unavoidable contradiction with the first two, which I will discuss separately.
Sketch Before Writing
Before writing code, I first sketched out three pages on a canvas: home page, article page, tags and archives, switching between Chinese and English, and light/dark themes in the design draft. This step took more time than I expected, but it determined the direction of all subsequent decisions—for example, the presence of a "Read Original" button in the design draft shaped the current multilingual solution.
There were only a few design principles: reading first, with a maximum body width of 720 px; one accent color; titles in serif, body in sans-serif, and code in monospace; dark mode does not simply invert colors but uses another set of contrast-checked tokens. The theme by default does not load Google Fonts, using the system Chinese font stack—loading Google Fonts in China would freeze the entire page.
Architecture: Four Components, One Container
Static site instead of CMS. The only reason for choosing Hugo is its friendliness for access in China. Static files can be fully cached, and if the source site goes down, it does not affect readers. The trade-off is no comments, no backend—which is not a drawback for a personal blog.
One container instead of three. Caddy, Hugo, receiving API, and cloudflared are all packed into the same node:22-alpine image. PID 1 is a Node script of over six hundred lines, which serves as both the HTTP API and process guardian (restarting child processes with exponential backoff on failure), as well as the translation queue. There are no npm dependencies and nothing to audit. The NAS only needs to mount two volumes: content/ and static/, which are the entirety of the blog.
Theme is the site. I did not use a pre-made theme but wrote one according to the design on the canvas: Hugo's new template system (layouts/baseof.html, home.html, page.html, etc.), and Obsidian's callout is rendered natively using Hugo's blockquote render hook (> [!tip]- collapsible), with code highlighting using Chroma class names paired with two color schemes, and images automatically bundled with width/height to avoid layout shifts.
What Happens During a Publish
The receiving API is minimal, all /api/* require Authorization: Bearer <token>:
| Method | Path | Function |
|---|---|---|
PUT | /api/posts/{lang}/{slug} | Create or completely replace an article (idempotent) |
DELETE | /api/posts/{lang}/{slug} | Unpublish, deleting derived machine translations |
GET | /api/posts | List of published articles |
POST | /api/rebuild · /api/translate | Force rebuild · complete translation |
GET | /healthz | Health check + last build + translation queue (no authentication required) |
What the server does: tokens are compared using timing-safe methods; slugs allow Unicode alphanumeric characters and -_, attachment names only allow common image/media extensions and cannot contain paths; writing first goes to a temporary directory and then rename; after a successful build to a temporary directory, two rename operations replace public/—if it fails, the old site remains online. The request body limit is 20 MB; exceeding this returns a 413 and actively closes the connection.
Plugin: Conversion Rules Are the Real Work
Publishing itself is an HTTP request, and 80% of the plugin's code is dedicated to converting Obsidian syntax to standard Markdown:
| Obsidian Syntax | After Publishing |
|---|---|
[[Note]], `[[Note | Alias]]` |
[[Note#Title]] | With anchor points, anchor rules consistent with Hugo |
| `![[image.png | Description |
![[Note]] | Inline one layer of text |
%% Comment %%, ^BlockID, dataview code blocks | Deleted |
callout, task lists, tables, $Formula$ | Kept as is, handled by Hugo |
| code blocks, inline code | Not touched at all |
The last point is the most important and also the easiest to get wrong—[[ appears in code blocks with some probability. The converter first splits by fenced code blocks, then skips inline code within each segment, only replacing the remaining text. This part is a pure function, covered by 20 test cases, which can be tested outside of Obsidian.
Three additional designs:
- Blog Directory. Specify a folder in the knowledge base (mine is
60-Blog) as the "working directory": notes inside are published by default, withpublish: falseexplicitly excluded, and notes outside are never published; subdirectories starting with_are ignored—drafts, templates, deployment scripts are all placed there. This relies on location rather than addingpublish: trueto each note, reducing one step to remember. - Idempotency. After publishing,
blog_url,blog_hash,blog_slug,blog_langare written back to frontmatter. Batch publishing skips unchanged notes based on hash; if the slug is changed, it republished, and the old address's copy is automatically deleted. - Preview. A command displays the frontmatter, Markdown, and attachment list that will be sent without actually sending it—when troubleshooting "why isn't this image showing," 90% of the answers are found here.
Another detail: after Hugo 0.144, the presence of the lang key in frontmatter causes the entire site build to fail. The plugin strips it, and the server deletes it again—two layers of defense, because the cost of this error is "all articles go offline."
Multilingual: One Write is Enough
When the English site first launched, there was only one article—everything else was in Chinese, and the English site only listed content with lang: en. Writing each piece twice is unrealistic, so I implemented a two-layer solution:
Machine translation is optional: fill in a key for an OpenAI-compatible interface or Anthropic interface in .env, and when the container starts, it scans to fill in missing translations, then translates during each publish. The translated page clearly indicates "machine translation" at the top and links back to the original; if a piece deserves a personal English version, just publish a note in Obsidian with the same slug and lang: en, and the machine version will automatically yield and never overwrite. Writing translate: false in the note can disable it for that piece. Using a small model to translate a two-thousand-word Chinese piece costs just a few cents.
Access in China: Being Accessible and Fast Are Two Different Things
This was clarified during the design phase but remains an imperfect solution.
Domains registered with Cloudflare cannot be filed for record. The filing requires the registrar to be on the Ministry of Industry and Information Technology's approval list, and Cloudflare is not; moreover, filing also requires a domestic cloud server, which my home NAS does not qualify for. So the "Cloudflare domain + home NAS" route has been from day one a non-filing, overseas solution.
Cloudflare's free nodes are "mostly reachable" in China. The differences between carriers are significant, and connections can occasionally be reset. Cloudflare's own statement also indicates that domestic users accessing overseas nodes will experience higher latency and packet loss. The China Network for businesses is not affordable for personal blogs.
| Level | Approach | Domestic Experience | Cost | Status |
|---|---|---|---|---|
| 1 | Cloudflare Tunnel direct connection | Reachable, not guaranteed fast | Domain fee | Now |
| 2 | Add a small VPS in Hong Kong for static mirroring, DNS-only pointing to it, bypassing Cloudflare proxy | Clearly more stable | A few dozen yuan per month | Next step |
| 3 | Transfer domain to a domestic registrar, file for record, connect to domestic CDN | Fast | Filing period + server | Discuss when readership increases significantly |
The benefits of a static site are most evident in Level 2: mirroring is just rsync of a directory, and if the NAS goes offline, readers won't notice.
Three Pitfalls Encountered
rsync is in restricted mode on NAS. The first version of the deployment script used rsync -az --delete for synchronization, and the NAS directly returned invalid path: 'obsidian-blog/'—its rsync runs in daemon mode and only recognizes shared folder paths, not user home directories. Switching to tar | ssh resolved the issue. Lesson: for NAS environments that are "not entirely Linux," the more primitive tools are more reliable.
Hugo extended does not run on Alpine. The Dockerfile downloaded hugo_extended, but it exited with code 127 at the hugo version step—"command not found." The file was clearly there, but the extended version dynamically links glibc, which Alpine does not have a corresponding loader for, causing the shell to report the command was not found. This theme does not require SCSS or encode WebP, so switching to the standard version (a statically linked pure Go binary) suffices.
A typo in the Caddyfile caused the entire site to refuse connection. @html path_regexp \.html$ / */—path_regexp only accepts one parameter, and I mistakenly provided three. Caddy failed to start, repeatedly restarted by the guardian process, and there was no process listening on port 80 inside the container, resulting in a connection refusal. I missed this during local testing because I didn't have the Caddy binary; later, I added the real Caddy's validate and a complete request cycle to be assured.
All three pitfalls share a common point: they occurred in areas where "I thought I had already verified." Configuration files also need testing—now the local smoke tests on the server will actually start Caddy and Hugo, checking the homepage, articles, tags, RSS, 404, and health checks.
Security Boundaries
- The receiving endpoint only recognizes Bearer tokens, which are stored in two places:
.envon the NAS anddata.jsonin the plugin— the latter is in the knowledge base, so if the knowledge base is synced via iCloud / Syncthing, it should be added to the exclusion list. - The container does not open any inbound ports (when using the tunnel), and cloudflared is an outbound connection.
- Caddy adds
X-Content-Type-Options,Referrer-Policy, and removes theServerheader;/api/*does not go into cache. - The API key used for translation is only inside the container, and the plugin never has access to it.
Current Status and Next Steps
- The container is running on the NAS, and publishing an article from shortcut key to page visibility takes about 5 seconds on the local network.
- The plugin is set up, and this article—along with its English version—was sent through this chain.
- The next steps in order: public domain + Tunnel; Hong Kong static mirror; then comments (most likely giscus, an old friend of static sites).
By the way, most of the code from that night was written in collaboration with AI—designs, containers, plugins, and this review are all part of it. It also makes mistakes in the Caddyfile, but it can find that line within ten minutes.