Sync mechanism of the blog
How does blog and note sync work?
In my previous attempts at creating blog pages, I tried git based solutions. But it was too much of a hassle to push everytime I needed to rephrase something.
At the same time I wanted a way to host my Obsidian notes somewhere.
So I settled with rsync based approach.
Here's the overview.
flowchart LR
A["Blog source"] --> B["Mirror (`personal/content/blog`)"]
C["Notes source"] --> D["Mirror (`personal/content/notes`)"]
B --> E["SvelteKit site reads content"]
D --> E
B -. "if remote configured" .-> F["Remote (`SYNC_REMOTE_BASE/blog`)"]
D -. "if remote configured" .-> G["Remote (`SYNC_REMOTE_BASE/notes`)"]
H["Watch mode (`--watch`)"] --> A
H --> C
To make it smoother on my end, I registered the file watcher as a MacOS service that starts in the background.
This way, whenever I make a change to my blog or to my Obsidian notes, they'll be reflected here immediately.
MacOS service definition
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.zet.hmzdotcom.syncwatch</string>
<key>ProgramArguments</key>
<array>
<string>/Users/zet/.bun/bin/bun</string>
<string>run</string>
<string>sync:watch</string>
</array>
<key>WorkingDirectory</key>
<string>/Users/zet/dev/html/hmzdotcom</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>ThrottleInterval</key>
<integer>10</integer>
<key>EnvironmentVariables</key>
<dict>
<key>HOME</key>
<string>/Users/zet</string>
<key>PATH</key>
<string>/Users/zet/.bun/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin</string>
</dict>
<key>StandardOutPath</key>
<string>/Users/zet/Library/Logs/hmzdotcom-syncwatch.out.log</string>
<key>StandardErrorPath</key>
<string>/Users/zet/Library/Logs/hmzdotcom-syncwatch.err.log</string>
</dict>
</plist>