article
Convert markdown stories to richtext through the Storyblok MCP, and diff every push
TL;DR Stories whose text is markdown inside blocks can be converted to Storyblok richtext offline and pushed as drafts through Storyblok's MCP server. The MCP has no file input, so every payload is retyped and slips happen: compare each draft with the converter output and re-push until there are 0 differences. Turn markdown-it's typographer off.
Moving 20 stories through the Storyblok MCP produced typing slips in two of them. One was a URL that came out as api.github.com/repos/… instead of github.com/…. The text still read fine.
The migration is five steps, and only one needs a human
The old blog was a Nuxt 2 static export with URLs of the form /a/<slug>/. Its space held 16 articles and 4 pages (home, about, license, legal notice). The old Article kept its text in a body field of nested bloks: ArticleText held markdown, ArticleCode a code string, ArticleImage an image with a caption and ArticleQuote a quote with a link. The new Article has one richtext field, content, and a short list of allowed interactive bloks.
From markdown bloks to richtext
Every story saved as JSON before any write.
Offline, from the backup, into richtext JSON.
updateStory with publish: false, typed through the MCP.
The draft read from the CDN, compared with the converter output.
A separate stage, only for stories with 0 differences.
The same flow as text:
Save each original story, using a field subset or stripping
preview_tokenfrom full responses.Convert the saved JSON to richtext on disk.
Push the result as a draft. The live story stays up.
Read the draft back from the CDN and compare it with the file from step 2.
Publish only what compares clean, then compare again.
Markdown converts with a library, minus its typographer
Storyblok publishes @storyblok/richtext with markdownToStoryblokRichtext and htmlToStoryblokRichtext, so there is no markdown parser to write. One option inside it has to go.
const md = new MarkdownIt({ html: false, linkify: true, typographer: false, breaks: true });
const markdownToStoryblokRichtext = (src) => htmlToStoryblokRichtext(md.render(src));} else if (b.component === 'ArticleImage') {
content.push({ type: 'blok', attrs: { id: randomUUID(), body: [{
_uid: randomUUID(), component: 'Figure', image: b.image, caption: b.caption ?? '', attribution: '' }] } });The other mappings are small:
Code. An
ArticleCodebecomes acode_blockwith a language from the old type string:ymltoyaml,jstojavascript,kttokotlin,mktomakefile,gradletogroovy,cplustocpp. Nine fences have no language, and the converter does not invent one.Images. An
ArticleImagebecomes aFigureblok. Caption and asset move over unchanged, soaltis whatever the old asset had, mostly empty.Quotes. An
ArticleQuotebecomes a blockquote followed by a paragraph that starts with an em dash and links to the source.Dropped on purpose. The trailing
## Feedbacksection and the hand-written series lists. The new site builds series navigation fromseriesandseries_part.
The check compares text, not layout: plain text from the old side (rendered with marked) against plain text from the new richtext, all whitespace stripped. 20 of 20 passed. That proves text and order, not nesting or heading levels, so open the pages too. In caching-in-ga the site's heading normalization (smallest heading becomes h2, jumps clamped to one level) turned sibling sections into parent and child, because the article opens with a deeper heading than it later uses.
The MCP retypes every payload, so every push needs a diff
The MCP has no file input. The converted stories, about 277 KB together, had to be typed into the calls, so each one is retyped. Slips came out of two of the 20 stories:
license: a duplicated, truncated first paragraph, noticed during the push.a/github-actions-context: a JSON code block whosestarred_urllost{/repo}.The same story again: one line of 260 where
"url": "https://github.com/mikepenz/release-changelog-builder-action"became"url": "https://api.github.com/repos/mikepenz/release-changelog-builder-action". The prebuilt payload file was correct, so the slip happened while typing.
The defence is a fixed order. Step through it and note where each slip would have gone live without the diff.
Step 1 of 5
Back up the originals
Save every story as JSON before any write. 19 were saved as a field subset and one in full with preview_token stripped.
Push drafts with publish false
Send new content, date, type, series and series_part with updateStory and publish: false. The update-story docs say false "does not unpublish a story that is already published". All 20 showed published: true with unpublished_changes: true, so the live site was untouched.
Diff the drafts mechanically
Read each draft from the CDN with ?version=draft, strip _uid, attrs.id and _editable, and compare with the converter output. Re-push until there are 0 differences.
Publish in a separate stage
Call publishStory for the 22 stories (the 20 plus two Series stories), series first, with no updateStory in that stage. Then compare again: published equals draft, and richtext equals the converter output.
Look at the live site
The index, the articles, the pages, the series, RSS and the sitemap returned 200 with the new titles and no leftover legacy body.
The _editable strip matters. The draft CDN adds a <!--#storyblok#...--> marker to blok bodies, and 9 of the 20 stories differed from the converter output on that alone. The mechanical diff caught the slips in a/github-actions-context, and only versions with 0 differences were published.
Dates fell back to the wrong field for 7 of 16 articles
A story has three date candidates: a date field, created_at and first_published_at. The first version of the new site fell back to first_published_at when date was missing. That was wrong for 7 of the 16 articles, and production showed those dates for a while after the cutover.
It looked like a timezone bug, because a preview and a production render of the same article were one day apart. It was not. Datetime fields in this space come back in UTC and the site renders the calendar day in Europe/Vienna. Migrated dates are stored as YYYY-MM-DD 00:00, which is 01:00 or 02:00 in Vienna, the same day.
Old URLs keep working with a middleware
The old URLs were /a/<slug>/ with a trailing slash, and /a/<slug> answered with a 301 to the slash form. A middleware keeps both (part 2 explains why it is not Astro's trailingSlash: 'always'). On the first deployment /a/adb-tricks/ returned 200 and /a/adb-tricks returned 301. Series have their own pages, /s/<series>/, and series parts are listed under the series, not individually on the index.
Deleting the old components is its own stage
With the content moved, the old body field and its components could go. Deleting components is destructive, so it ran in two stages, the second only after an explicit go from me. First, without touching the schema:
Save the old component schemas (
ArticleText,ArticleCode,ArticleImage,ArticleQuote,ArticleReferences,intro,Newsletter,page,TextSection, plus the oldbodyfield definitions) tomigration/backup/components-old.json.Strip the legacy
bodyfrom the six stories that still had it, publish, and check each result on the CDN.Scan all 22 stories on the draft CDN: no
bodykey left, and no old component in use except lowercasepage, still the root component of the four pages.
Then the schema change: re-check that none of the eight old components is used at any depth, remove only the body field from Article and Page, and delete the eight components one at a time, re-listing after each. A read-only listing confirms the result:
⏺ execute_readonly operation="listManagementComponents" parameters={"space_id":93903} fields=["components.name"] region="eu" {"components":[{"name":"Article"},{"name":"Callout"},{"name":"CodeTab"},{"name":"CodeTabs"},{"name":"EdgeProbe"},{"name":"Figure"},{"name":"FlowNode"},{"name":"page"},{"name":"Page"},{"name":"RequestFlow"},{"name":"Series"},{"name":"Step"},{"name":"Steps"},{"name":"Terminal"},{"name":"TermLine"}]}
ArticleCode, ArticleImage, ArticleQuote, ArticleReferences, ArticleText, intro, Newsletter and TextSection are gone. Lowercase page stays.
The schema backup was typed from MCP output, so the same no-file-input risk applies to it, and it misses the preview_field that intro had.
Try it yourself
Paste this into Claude Code with the Storyblok MCP connected. It converts offline, pushes drafts and diffs them, and leaves publishing and schema changes to you.
Convert Storyblok stories to richtext, push drafts, diff to 0
Convert my Storyblok stories from markdown bloks to a richtext field and push them as drafts. Space <space-id>, region <region>, stories <list of full_slugs>, target field <richtext-field>.
Rules:
- Never print, log or commit a token. Read STORYBLOK_PREVIEW_TOKEN and STORYBLOK_REGION from the environment and report only counts and status codes.
- Drafts only: updateStory with publish: false. Do not publish, unpublish, delete or change the schema.
- Use search, then describe, before every MCP operation, and pass fields to keep responses small.
Steps. Finish each one and show the result before the next:
1. Back up every story as JSON to <backup-dir> (strip preview_token). Write nothing to Storyblok yet.
2. Convert the saved markdown to richtext JSON in <out-dir> with @storyblok/richtext. Build markdown-it with typographer: false and pass its HTML to htmlToStoryblokRichtext. Check that plain text, whitespace stripped, equals the old side. Tell me which stories failed.
3. Ask me before the first push. Then push each story as a draft. The MCP has no file input, so you retype each payload: expect slips.
4. Write a read-only script that fetches each draft from the CDN with ?version=draft, removes _uid, attrs.id and _editable, and compares it with the file in <out-dir>. Print the number of differences per story and the first differing path.
5. Re-push every story with differences and diff again until all report 0. Do not publish.
6. List the stories ready to publish and what you did not verify.Requirements: the Storyblok MCP (OAuth, no token), a preview access token in your environment, and the source content on disk.
Good to know
The package's own markdown parser needs a DOM, which Workers lack, as far as I know, and the docs do not say.
The text check does not prove nesting or heading levels. Alt text for the 2020 screenshots is still empty.
I did not check external links to old pages beyond the site's own URLs.
A pushed draft of a published story shows
unpublished_changes: trueuntil you publish it.
Run your diff on one story before you push the other nineteen.