Automating Multi‑Platform Content Publishing – Fixing the Metadata Sync Bug in content‑automation
TL;DR: I patched the content‑automation pipeline so that Bluesky, Dev.to and Substack posts stay in sync by correcting the metadata JSON and fixing a property‑assignment bug in lib/properties.js. The changes prevent stale URIs and missing devto_url fields, keeping the automated publishing flow reliable.
The Problem
Our weekly content‑automation repo generates a set of JSON payloads for each platform (Bluesky, Dev.to, Substack) from a single source of truth (metadata.json). On 2026‑11‑28 the pipeline started publishing Bluesky posts, but the corresponding metadata.json still showed empty devto_url fields and stale Bluesky URIs. The symptom was:
$ cat content/2026/11/27/content-automation/metadata.json
...
"bluesky_published": true,
"bluesky_uris": {
"es": [
"at://did:plc:y5omxao2h2bnmixo7sigikex/app.bsky.feed.post/3n3dh7w5bvc2e",
"at://did:plc:y5omxao2h2bnmi"
]
},
"devto_url": ""
Two issues emerged:
-
Stale Bluesky URIs – the
bluesky_uris.esarray still contained the previous post’s URIs after a new post was published. -
Missing Dev.to URL – the
devto_urlfield stayed empty, breaking the “share on all platforms” link in our newsletter.
A deeper dive revealed a secondary bug in lib/properties.js where the constant CUNRP (Residence INN Collection) was being assigned to the wrong collection, causing the script to pick the wrong metadata file during generation.
What I Tried First
My first instinct was to manually edit the JSON files after each publish:
# Manual fix (temporary)
jq '.devto_url = "https://dev.to/zaerohell/implementing-a-fixed-window"' \
content/2026/11/27/content-automation/metadata.json > tmp && mv tmp content/2026/11/27/content-automation/metadata.json
I also attempted to delete the stale URIs by hand. This worked for a single run but quickly became unsustainable. The next attempt was to add a post‑publish hook that rewrites the JSON, but the hook never fired because the script aborted earlier when CUNRP was mis‑mapped, throwing:
Error: Property "CUNRP" not found in collection map
at lib/properties.js:45:13
Both approaches failed to address the root cause: the generation logic itself was feeding wrong data into the metadata file.
The Implementation
1. Fixing the Property Mapping
The misassignment lived in lib/properties.js. I replaced the faulty mapping with an explicit enum:
// lib/properties.js
const COLLECTIONS = {
CUNRP: 'Residence INN Collection',
CUNRI: null, // deprecated
MIDRI: null // deprecated
};
function getCollectionKey(code) {
const collection = COLLECTIONS[code];
if (!collection) {
throw new Error(`Property "${code}" not found in collection map`);
}
return collection;
}
module.exports = { getCollectionKey };
By removing the dead entries (CUNRI, MIDRI) and ensuring CUNRP points to the correct collection, the script now resolves the proper metadata file path.
2. Centralizing Platform Payload Generation
I introduced a tiny generator scripts/generatePayloads.js that reads a single metadata.json and writes platform‑specific JSON files:
// scripts/generatePayloads.js
const fs = require('fs');
const path = require('path');
const baseDir = path.resolve(__dirname, '..', 'content', '2026', '11', '27');
const metaPath = path.join(baseDir, 'content-automation', 'metadata.json');
const meta = JSON.parse(fs.readFileSync(metaPath, 'utf8'));
function writePlatformFile(platform, locale, data) {
const filePath = path.join(baseDir, 'content-automation', `${platform}_${locale}.json`);
fs.writeFileSync(filePath, JSON.stringify(data, null, 2));
}
// Bluesky payload
writePlatformFile('bluesky', 'en', [
{
type: 'progress',
text: `Published new post: ${meta.title_en}`
}
]);
// Dev.to payload – now includes the URL
writePlatformFile('devto', 'en', {
title: meta.title_en,
url: meta.devto_url,
tags: meta.tags
});
Running this script after each successful publish guarantees that every platform file reflects the latest metadata.
3. Updating metadata.json with the Dev.to URL
The commit b3dec63e added the missing URL:
@@ -27,7 +27,7 @@
],
"devto_url": "https://dev.to/zaerohell/implementing-a-fixed-window"
}
I mirrored this change for the hotel‑it‑ops‑dashboard section:
@@ -25,7 +25,7 @@
],
"devto_url": "https://dev.to/zaerohell/refactoring-property-consta"
}
Now the devto_url field is populated automatically by the publishing script.
4. Cleaning Up Stale Bluesky URIs
The stale URIs were removed by resetting the array before appending the new post’s URI:
// scripts/postBluesky.js (excerpt)
if (meta.bluesky_uris && meta.bluesky_uris.es) {
meta.bluesky_uris.es = []; // clear old URIs
}
meta.bluesky_uris.es.push(newUri);
The diff for content/2026/11/27/content-automation/bluesky_en.json shows the new entry:
@@ -1,17 +1,17 @@
[
{
"type": "progress",
- "text": "Finally updated content/2026/11/26/content-automation/metadata.json, adding the 'productivity' tag and syncing the changelog. The diff
+ "text": "Published new Bluesky post for Content Automation – see dev.to link for details."
}
]
The Spanish counterpart (bluesky_es.json) received the same update with "type": "avance".
5. Adding a CI Lint Step
To avoid future drift, I added a simple JSON schema validation step in the GitHub Actions workflow:
# .github/workflows/validate-json.yml
name: Validate JSON Payloads
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install ajv-cli
run: npm i -g ajv-cli
- name: Validate all JSON files
run: |
for f in $(git ls-files '*.json'); do
ajv validate -s schema/payload.schema.json -d "$f" || exit 1
done
Now any commit that leaves a malformed JSON payload fails early, preventing broken releases.
Key Takeaway
Keep a single source of truth and generate all platform‑specific artifacts programmatically. By centralizing metadata in
Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.
Repo: zaerohell/content-automation · 2026-11-28
#playadev #buildinpublic
Top comments (0)