Automating Multi‑Platform Content Publishing with a Node.js Generator and GitHub Actions
TL;DR: I built a small Node.js generator that turns a single metadata.json entry into ready‑to‑publish Markdown for Medium/Substack and JSON payloads for Bluesky, then wired it to a GitHub Action. The result is a zero‑touch daily content push that keeps every platform in sync.
The Problem
Our content-automation repo stores raw copy for three publishing channels (Medium, Substack, Bluesky) in separate markdown and JSON files. Every morning we had to:
- Manually copy the same article body into three different files.
- Flip the
medium_generated/substack_generatedflags inmetadata.jsonafter each publish. - Run a fragile Bash one‑liner to upload the Bluesky JSON payload, often hitting “
Unexpected token” errors because the file wasn’t properly escaped.
The symptom was a growing backlog of duplicated copy and a CI log littered with SyntaxError: Unexpected token when the Bluesky upload step failed. The root cause was the lack of a single source of truth and an automated transformation pipeline.
What I Tried First
My first attempt was a quick shell script (scripts/sync.sh) that used sed to replace placeholders in the markdown templates:
#!/bin/bash sed "s/{{title}}/$TITLE/g" templates/medium.tpl > content/$DATE/medium_en.md # repeat for Substack and Bluesky It worked for a single article but broke as soon as we added multilingual support. The script didn’t understand JSON escaping, and any missing placeholder caused the whole CI job to fail with:
sed: -e expression #1, char 15: unknown option to `s' I also tried a Python one‑liner to generate the Bluesky payload, but the extra runtime dependency added friction to the repo and the CI environment.
The Implementation
1. Design a tiny generator
I introduced a new Node.js script scripts/generateContent.js. The script reads a single metadata.json entry, pulls the body from a master Markdown (content/master/ai-enterprise-automation-lab.md), and writes out the platform‑specific files.
// scripts/generateContent.js const fs = require('fs'); const path = require('path'); const DATE = new Date().toISOString().slice(0, 10); // e.g. 2026-11-18 const ROOT = path.resolve(__dirname, '..', 'content', DATE, 'ai-enterprise-automation-lab'); const metaPath = path.join(ROOT, 'metadata.json'); const meta = JSON.parse(fs.readFileSync(metaPath, 'utf8')); const masterPath = path.resolve(__dirname, '..', 'content', 'master', 'ai-enterprise-automation-lab.md'); const masterBody = fs.readFileSync(masterPath, 'utf8'); // Helper to write a file only if content changed function writeIfChanged(file, content) { if (fs.existsSync(file) && fs.readFileSync(file, 'utf8') === content) return; fs.writeFileSync(file, content); console.log(`✏️ Updated ${path.relative(process.cwd(), file)}`); } // 1️⃣ Medium (English) const mediumEn = `# ${meta.title}\n\n${masterBody}`; writeIfChanged(path.join(ROOT, 'medium_en.md'), mediumEn); // 2️⃣ Medium (Spanish) – simple i18n stub const mediumEs = `# ${meta.title_es || meta.title}\n\n${masterBody.replace(/AI/g, 'IA')}`; writeIfChanged(path.join(ROOT, 'medium_es.md'), mediumEs); // 3️⃣ Substack payloads (just the body for now) writeIfChanged(path.join(ROOT, 'substack_en.md'), masterBody); writeIfChanged(path.join(ROOT, 'substack_es.md'), masterBody); // 4️⃣ Bluesky JSON payloads function blueskyPayload(lang, body) { return JSON.stringify({ text: `${meta.title} – ${lang.toUpperCase()}\n\n${body}`, createdAt: new Date().toISOString(), tags: meta.tags || [] }, null, 2); } writeIfChanged(path.join(ROOT, 'bluesky_en.json'), blueskyPayload('en', masterBody)); writeIfChanged(path.join(ROOT, 'bluesky_es.json'), blueskyPayload('es', masterBody)); // 5️⃣ Flip the generated flags meta.medium_generated = true; meta.substack_generated = true; fs.writeFileSync(metaPath, JSON.stringify(meta, null, 2)); console.log('✅ metadata.json flags updated'); Key points:
- Single source of truth –
metadata.jsonholds the title, tags, and flags. The master Markdown holds the article body. - Idempotent writes –
writeIfChangedprevents unnecessary diffs, keeping the repo clean. - JSON safety –
JSON.stringifyguarantees a valid Bluesky payload, eliminating theUnexpected tokenerrors we saw before.
2. Wire it into GitHub Actions
I added a workflow /.github/workflows/content.yml that runs on a schedule (every day at 06:00 UTC) and on pushes to main.
name: Content Automation on: schedule: - cron: '0 6 * * *' # 06:00 UTC daily push: branches: [main] jobs: generate: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Set up Node uses: actions/setup-node@v3 with: node-version: '20' - name: Install deps run: npm ci - name: Run generator run: node scripts/generateContent.js - name: Commit changes uses: stefanzweifel/git-auto-commit-action@v4 with: commit_message: "chore(content): auto-generate ${{ github.run_id }} [skip ci]" branch: main file_pattern: "content/**" The git-auto-commit-action automatically creates a commit only when the generator actually changed a file, preventing empty commits.
3. Verify the diff – what the CI produced
After the first run on 2026‑11‑18 the diff looked exactly like the three commits we see in the repo:
+## [2026-11-17] ai-enterprise-automation-lab + +### Added +- **Sentry live monitoring** for the AI Gateway (projects `ai-lab-gateway`, `ai-lab-iso-auditor`). Documented in `CHANGELOG …and the new platform files:
+I was staring at a blinking red line in the CI logs for the third night in a row... The metadata.json change is also captured:
- "medium_generated": false, - "substack_generated": false, + "medium_generated": true, + "substack_generated": true, All three Bluesky JSON payloads (bluesky_en.json, bluesky_es.json) are now present and valid:
{ "text": "AI Enterprise Automation Lab – EN\n\nI was staring at a blinking red line ...", "createdAt": "2026-11-18T06:00:00.000Z", "tags": ["AI", "Automation", "Sentry"] } No more syntax errors
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-18
#playadev #buildinpublic


