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 import statements, making it native to our Astro project.
  • gray-matter Integration: The script parses YAML frontmatter to extract titles, tags, and SEO metadata automatically.
  • Markdown-to-HTML Conversion: I integrated the marked library to transform raw Markdown into HTML, ensuring StoryChief renders headers, lists, and bold text correctly.
  • Safe by Design: I added a --dry-run flag to test the payload before sending it to the API, and the script always defaults to draft status 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:

  1. Identified the require vs import incompatibility.
  2. Refactored the script while maintaining the user's preference for the .js extension.
  3. Debugged a missing content formatting issue by implementing on-the-fly HTML conversion.
  4. Corrected the API version path from v1 to 1.0 based on live curl feedback.
  5. Integrated the new tool into an existing .agent/workflows/wrap.md automation.

Key Takeaways

  • Consistency is King: Mixing CommonJS and ESM can lead to headaches. Pick one and stick to it (or use .mjs for clarity).
  • Automate the "Boring" Stuff: By adding one prompt to our /wrap workflow, 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.