Automating Blog Publishing With Hugo, n8n & Obsidian: One Year Later Link to heading

A year ago I wrote about automating my blog publishing: write in Obsidian, move the note to Published/, and n8n commits it to my Hugo repo. That post ended with “even while writing this post, I found improvements I want to add.”

This is that update. The idea is the same, but nearly every piece has changed. Some changes were planned; others came from finding out what the original design got wrong.


What Stayed the Same Link to heading

The core pipeline still looks like this:

Obsidian → Syncthing → Proxmox LXC → n8n → GitHub → Hugo → GitHub Pages

  • I write in Obsidian on any device.
  • Syncthing syncs the vault to a container on my Proxmox server.
  • n8n (in another container) copies the blog folders into a local clone of the Hugo repo, normalises them, commits and pushes.
  • A GitHub Action builds the site with Hugo and deploys it to GitHub Pages.

The “move a file to publish” workflow is still the best part of the setup, and I didn’t touch it.


What Changed Link to heading

1. The vault was reorganised Link to heading

I restructured my whole vault into a Personal/Work split with PARA inside each half (that’s its own post). The blog now lives at:

Personal/Blog/
├── Draft/        work in progress, never synced to the repo
├── Published/    → content/posts
└── Projects/     → content/projects

Moving the folders meant updating the n8n workflows at the same time. Because the pipeline uses rsync --delete, the order mattered (more on that below).

2. Images: publish only what a post uses Link to heading

This was the biggest problem with the original setup, and it wasn’t in the first post because I didn’t see it.

Originally, a separate “Media” workflow mirrored my entire attachments folder into static/Assets/ in the Hugo repo. It worked because every image a post needed was there. But so was everything else in that folder: templates, PDFs, drawings, sync-conflict copies, files that had nothing to do with the blog.

The repo is public. So all of that was public too.

The fix was to flip the model: the sync script now decides which images to publish by reading the posts themselves. It:

  1. finds every image embed in a post (both Obsidian ![image](/Assets/Files/image.png) and Markdown ![alt](/Assets/Files/image.png), skipping fenced code blocks)
  2. rewrites each one to a stable URL, /Assets/Files/<name>
  3. looks the file up by name in the attachments folder and copies only those files into the repo
  4. prunes every file under static/Assets/ that no page in content/ links to

Here is the core of the rewrite:

const URL_PREFIX = '/Assets/Files';
const IMG = /\.(png|jpe?g|gif|webp|svg|avif|bmp)$/i;

function rewriteImages(body, used) {
  const link = (alt, name) => {
    used.add(name);
    return `![${alt}](${URL_PREFIX}/${encodeURIComponent(name)})`;
  };
  // odd chunks are fenced code blocks: leave them alone
  return body.split(/(^```[\s\S]*?^```)/m).map((chunk, i) => {
    if (i % 2) return chunk;
    chunk = chunk.replace(/!\[\[([^\]|#]+)(?:[|#][^\]]*)?\]\]/g, (m, name) => {
      const base = path.basename(name.trim());
      return IMG.test(base) ? link(base.replace(IMG, ''), base) : m;
    });
    return chunk.replace(/!\[([^\]]*)\]\(((?:[^()\s]|\([^()]*\))+)\)/g, (m, alt, target) => {
      if (/^[a-z]+:/i.test(target)) return m; // external URL
      const base = path.basename(decodeURIComponent(target.split('#')[0]));
      return IMG.test(base) ? link(alt, base) : m;
    });
  }).join('');
}

A nice side effect: I write posts with normal Obsidian embeds, and they render both in Obsidian and on the site. In the old setup I had to keep fragile relative paths like ../../../../Assets/Files/… working.

The first run after the change removed 72 files from the repo. The Media workflow is now switched off for good.

One lesson I’m still acting on: deleting files from a repo doesn’t remove them from its history. If something private ever lands in a public repo, cleaning it up properly means rewriting history (git filter-repo) and force-pushing, not just a new commit.

3. Guards against wiping the site Link to heading

The original workflow ran rsync --delete from the synced folder into the repo, then deleted every post in the repo that wasn’t in the source. Think about what happens if the source folder is empty: half-way through a Syncthing sync, after a folder rename, or after a mistake on my phone. The pipeline would faithfully delete every post and push.

There are now two independent guards:

  • the SSH step checks that the source folder has Markdown files before running rsync, and fails the run otherwise:
SRC=/root/Obsidian/obsidian-notes/Personal/Blog/Published
ls "$SRC"/*.md >/dev/null 2>&1 || { echo "no posts in $SRC, refusing to sync" >&2; exit 1; }
rsync -av --delete "$SRC"/ /mnt/shared-blog/published
  • sync.js refuses to run when its source folder has no .md files, and exits non-zero:
const sources = fs.readdirSync(srcDir).filter(f => f.endsWith('.md'));
if (sources.length === 0)
  throw new Error(`no .md files in ${srcDir}; refusing to sync (would delete everything)`);

For planned changes like moving folders, the procedure is: pause the workflows, move the folders, update the paths in n8n, wait for Syncthing to report 100% on the server, then turn the workflows back on.

4. Commits only when something changed Link to heading

The push step now stages the content and media folders and exits early if nothing is staged:

cd /mnt/shared-blog/hugo && \
git add content/posts static/Assets && \
git diff --cached --quiet && exit 0 || \
(git commit -m "Sync Blog posts: …" && git push --force)

The commit message lists the updated and deleted files from sync.js’s JSON output, so the repo history doubles as a publishing log.

5. Ready for n8n v3 Link to heading

n8n’s v3 migration report flagged both workflows: the old Cron node is removed in v3, and workflows that use it would simply stop running after the upgrade. The replacement is the Schedule Trigger node with a 15-minute interval. It’s a two-minute change, but the failure would have been silent, so it’s worth checking your own workflows for the same thing.

6. One canonical copy of the script Link to heading

sync.js used to exist only on the n8n container. Now the canonical copy lives in my vault at _System/scripts/sync.js and gets deployed to /mnt/shared-blog/scripts/. It’s versioned by Syncthing like every other note, and I edit it in the same place I write posts.


The Current Workflow Link to heading

Each of the two workflows (posts and project pages) runs every 15 minutes:

  1. Schedule Trigger (every 15 minutes)
  2. Git pull in the local Hugo clone
  3. SSH: guard + rsync the blog folder and the attachments to the shared mount
  4. sync.js: normalise frontmatter (draft: false, default author and date), rewrite image embeds, copy used images, delete removed posts, prune unused media
  5. If anything changed: commit with a generated message and push; otherwise do nothing

sync.js usage, for reference:

sync.js <srcDir> <dstDir>
        [--attachments <dir>]           where vault attachments live
        [--static <dir>]                Hugo static dir served at /Assets/Files
        [--prune <dir> --content <dir>] remove media no page links to

What’s Still Rough Link to heading

  • Both workflows share one Git clone and run on the same schedule, so they can occasionally race each other on pull or push. Merging them into one workflow (or offsetting their schedules) would fix it.
  • git push --force is a leftover from the first version. With a single writer it’s harmless, but a normal push would fail loudly instead of silently overwriting history.
  • Missing images only show up in the logs. sync.js reports them in missingMedia, but nothing alerts me. A broken image can sit on the site until I notice it.

Takeaways Link to heading

  • Treat a public repo as a publishing target, not a backup. Anything that reaches it is published, including its history. Publish an allow-list (what posts actually use), never a whole folder.
  • Every --delete needs a guard. Sync tools see a half-synced folder as “the user deleted everything”.
  • Read your platform’s migration reports. The Cron removal would have broken publishing without a single error message.

The pipeline is still “move a file and forget about it”. It’s just a lot harder to hurt myself with now.