Automate StoryChief publishing: From Markdown to CMS Format
• By Rich Martinez
Streamlining the Workflow: Automating StoryChief Publishing from Markdown
The Problem
Maintaining a blog often feels like double the work. First, you write the content in your favorite editor (markdown, of course), and then you have to manually copy-paste it into a CMS like StoryChief, re-attach images, and re-format everything. I wanted a "zero-touch" workflow where wrapping up a coding session automatically drafts a blog post for me and sends it directly to StoryChief.
The Solution
I developed a Node.js publishing script that bridges the gap between local markdown files and the StoryChief API.
Key Technical Details:
- Refactored to ES Modules: I modernized the script to use
importstatements, making it native to our Astro project. gray-matterIntegration: The script parses YAML frontmatter to extract titles, tags, and SEO metadata automatically.- Markdown-to-HTML Conversion: I integrated the
markedlibrary to transform raw Markdown into HTML, ensuring StoryChief renders headers, lists, and bold text correctly. - Safe by Design: I added a
--dry-runflag to test the payload before sending it to the API, and the script always defaults todraftstatus in StoryChief. - API Version Discovery: through iterative testing, we discovered the correct REST endpoint version is
1.0.
// Example of how we create the story payload
const payload = {
title: title,
content: content,
tags: metadata.tags || [],
status: 'draft', // Always safe!
};
The AI Angle
This session was a classic example of iterative refactoring. I started with an existing CommonJS script and needed to integrate it into a project that defaults to ES Modules ("type": "module"). The AI successfully:
- Identified the
requirevsimportincompatibility. - Refactored the script while maintaining the user's preference for the
.jsextension. - Debugged a missing content formatting issue by implementing on-the-fly HTML conversion.
- Corrected the API version path from
v1to1.0based on live curl feedback. - Integrated the new tool into an existing
.agent/workflows/wrap.mdautomation.
Key Takeaways
- Consistency is King: Mixing CommonJS and ESM can lead to headaches. Pick one and stick to it (or use
.mjsfor clarity). - Automate the "Boring" Stuff: By adding one prompt to our
/wrapworkflow, we've removed the friction of moving content from Git to the CMS. - Dry-Runs Save Lives: Always implement a mock or dry-run mode when working with external APIs.