Automating Multi‑Platform Content Publishing with a Node.js Generator and Structured Metadata
TL;DR: I refactored our content‑automation repo to generate platform‑specific files (Medium, Substack, Bluesky) from a single source of truth and added a metadata flag that lets the CI know when a piece is ready. The change removes manual copy‑pastes and guarantees every language version is published in lockstep.
The Problem
Our CI pipeline was failing on the content-automation step because the generator script only produced the English Medium markdown. The Spanish version, the Substack copy, and the Bluesky JSON payload were missing, causing the downstream publish jobs to abort with errors like:
Error: ENOENT: no such file or directory, open 'content/2026/11/18/content-automation/medium_es.md'
The root cause was a lack of a unified generation process. Each platform required its own file format (Markdown for Medium/Substack, JSON for Bluesky) and language variant, but the script was hard‑coded to emit only one file and never updated the metadata.json flags that downstream jobs read to decide whether to run. The result was a broken pipeline and a lot of manual copy‑pasting.
What I Tried First
My first attempt was to duplicate the existing generation logic inside the CI YAML, adding a step that cp‑ed the English markdown to the Spanish path and created empty JSON files for Bluesky.
- name: Duplicate Medium files for Spanish
run: |
cp content/.../medium_en.md content/.../medium_es.md
echo '{}' > content/.../bluesky_en.json
echo '{}' > content/.../bluesky_es.json
That hack worked temporarily, but it introduced two major problems:
- No source of truth – any typo or missing translation had to be fixed in two places.
-
Metadata flags stayed false – downstream jobs still saw
"medium_generated": falseand aborted.
I needed a proper generator that could read a single source file, apply language templates, and update the metadata atomically.
The Implementation
1. Architecture Overview
src/
├─ generate.js ← entry point
├─ templates/
│ ├─ medium.md ← Handlebars template (English)
│ ├─ medium.es.md ← Handlebars template (Spanish)
│ ├─ substack.md
│ └─ substack.es.md
└─ parsers/
└─ parser.mjs ← CSV parser used by monitor‑parches‑uhpcm
content/
└─ 2026/11/18/
├─ content-automation/
│ ├─ metadata.json
│ ├─ medium_en.md ← generated
│ ├─ medium_es.md ← generated
│ ├─ substack_en.md ← generated
│ ├─ substack_es.md ← generated
│ ├─ bluesky_en.json
│ └─ bluesky_es.json
The generator reads metadata.json, pulls the raw article body from src/templates/*.md, renders it for each language, writes the appropriate files, and finally flips the *_generated flags to true.
2. metadata.json Before & After
Before (commit 33040751, line 12‑15):
{
"pull_requests": 0,
"releases": 0,
"closed_issues": 0,
"medium_generated": false,
"substack_generated": false,
"bluesky_generated": false
}
After (same commit, updated lines):
{
"pull_requests": 0,
"releases": 0,
"closed_issues": 0,
"medium_generated": true,
"substack_generated": true,
"bluesky_generated": true
}
The generator is the only place that mutates these flags, guaranteeing consistency.
3. Core Generator (src/generate.js)
#!/usr/bin/env node
import fs from 'fs/promises';
import path from 'path';
import Handlebars from 'handlebars';
// -------------------------------------------------------------------
// Helpers
// -------------------------------------------------------------------
const readJSON = async (file) => JSON.parse(await fs.readFile(file, 'utf8'));
const writeFile = async (file, data) => {
await fs.mkdir(path.dirname(file), { recursive: true });
await fs.writeFile(file, data, 'utf8');
};
// -------------------------------------------------------------------
// Main
// -------------------------------------------------------------------
(async () => {
const root = path.resolve(import.meta.url, '../../content/2026/11/18/content-automation');
const metaPath = path.join(root, 'metadata.json');
const meta = await readJSON(metaPath);
// Load templates (English + Spanish)
const tmpl = {
mediumEn: await fs.readFile('src/templates/medium.md', 'utf8'),
mediumEs: await fs.readFile('src/templates/medium.es.md', 'utf8'),
substackEn: await fs.readFile('src/templates/substack.md', 'utf8'),
substackEs: await fs.readFile('src/templates/substack.es.md', 'utf8')
};
// Compile once
const compile = (src) => Handlebars.compile(src);
// Render for each language
const rendered = {
medium_en: compile(tmpl.mediumEn)({ meta }),
medium_es: compile(tmpl.mediumEs)({ meta }),
substack_en: compile(tmpl.substackEn)({ meta }),
substack_es: compile(tmpl.substackEs)({ meta })
};
// Write markdown files
await Promise.all([
writeFile(path.join(root, 'medium_en.md'), rendered.medium_en),
writeFile(path.join(root, 'medium_es.md'), rendered.medium_es),
writeFile(path.join(root, 'substack_en.md'), rendered.substack_en),
writeFile(path.join(root, 'substack_es.md'), rendered.substack_es)
]);
// Create Bluesky JSON payloads (simple wrapper)
const blueskyPayload = (lang) => ({
type: 'post',
language: lang,
title: meta.title,
content: rendered[`medium_${lang}`] // reuse Medium rendering
});
await Promise.all([
writeFile(path.join(root, 'bluesky_en.json'), JSON.stringify(blueskyPayload('en'), null, 2)),
writeFile(path.join(root, 'bluesky_es.json'), JSON.stringify(blueskyPayload('es'), null, 2))
]);
// Flip flags atomically
const updatedMeta = {
...meta,
medium_generated: true,
substack_generated: true,
bluesky_generated: true
};
await writeFile(metaPath, JSON.stringify(updatedMeta, null, 2));
console.log('✅ Content generation complete.');
})().catch(err => {
console.error('❌ Generation failed:', err);
process.exit(1);
});
Why this file matters:
- All platform files are produced from the same Handlebars context (
meta).
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-19
#playadev #buildinpublic
Top comments (0)