Content migration between platforms

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Content migration between platforms is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. KB content migration — Notion → markdown (notion-to-md), Confluence → CommonMark (confluence-to-markdown), Zendesk/Intercom → markdown via REST + turndown/markdownify, Salesforce Knowledge → CSV → markdown. Preserves frontmatter, attachments, redirects. Use when changing KB platform.

How to use this skill

Skill file

Content migration between KB platforms

When to use

User says "migrate KB from Notion to Docusaurus", "leave Confluence", "Zendesk to Helpdesk", "consolidate KBs", "we're switching docs platforms". Reach BEFORE the cutover date and AFTER the destination IA is designed (taxonomy skill).

Setup

# Notion → md
npm i -g notion-to-md
# or richer alternative
npm i -g @notion-stuff/v4-types notion-to-md

# Confluence → md
npm i -g confluence-to-markdown

# Generic HTML → md
pip install markdownify
# or
npm i -g turndown

# Useful tooling
pipx install httpx tenacity python-frontmatter
brew install pandoc       # for docx / rST source

Auth / API key requirements:

Common recipes

Recipe 1: Notion → markdown

# Single page
node -e "
const { Client } = require('@notionhq/client');
const { NotionToMarkdown } = require('notion-to-md');
const notion = new Client({ auth: process.env.NOTION_TOKEN });
const n2m = new NotionToMarkdown({ notionClient: notion });
(async () => {
  const blocks = await n2m.pageToMarkdown('$PAGE_ID');
  const md = n2m.toMarkdownString(blocks);
  console.log(md.parent);
})()
" > docs/page.md

# Whole database (each row = an article)
node scripts/notion-db-export.js > exported-pages.json

Recipe 2: Notion database recursive export

// scripts/notion-db-export.js
const { Client } = require('@notionhq/client');
const { NotionToMarkdown } = require('notion-to-md');
const fs = require('fs');
const notion = new Client({ auth: process.env.NOTION_TOKEN });
const n2m = new NotionToMarkdown({ notionClient: notion });
n2m.setCustomTransformer('callout', async (block) => {
  return `:::note\n${block.callout.rich_text.map(t=>t.plain_text).join('')}\n:::`;
});
(async () => {
  let cursor = undefined;
  do {
    const r = await notion.databases.query({
      database_id: process.env.DB_ID,
      start_cursor: cursor,
    });
    for (const page of r.results) {
      const title = page.properties.Title.title[0].plain_text;
      const slug = title.toLowerCase().replace(/[^a-z0-9]+/g,'-');
      const blocks = await n2m.pageToMarkdown(page.id);
      const body = n2m.toMarkdownString(blocks).parent;
      const fm = `---\ntitle: "${title}"\nslug: ${slug}\nstatus: published\nlast_verified: ${page.last_edited_time.slice(0,10)}\n---\n\n`;
      fs.writeFileSync(`docs/imported/${slug}.md`, fm + body);
    }
    cursor = r.next_cursor;
  } while (cursor);
})();

Recipe 3: Confluence → markdown

# Spaces / pages listing
curl -G "https://${SITE}.atlassian.net/wiki/rest/api/content" \
  -u "${CONFLUENCE_USER}:${CONFLUENCE_API_TOKEN}" \
  --data-urlencode "spaceKey=DOCS" \
  --data-urlencode "expand=body.storage,ancestors,version" \
  --data-urlencode "limit=100" \
  > confluence-pages.json

# Convert each page's storage format → markdown
python scripts/confluence-export.py
# scripts/confluence-export.py
import json, pathlib, html2text, frontmatter
h = html2text.HTML2Text()
h.body_width = 0
h.ignore_links = False
pages = json.load(open('confluence-pages.json'))['results']
for pg in pages:
    title = pg['title']
    slug = title.lower().replace(' ','-')
    md = h.handle(pg['body']['storage']['value'])
    post = frontmatter.Post(md, title=title, slug=slug,
        confluence_id=pg['id'],
        last_modified=pg['version']['when'][:10])
    pathlib.Path(f"docs/imported/{slug}.md").write_text(frontmatter.dumps(post))

Recipe 4: Zendesk Guide → markdown

# List articles (paginate)
NEXT="https://${ZENDESK_SUBDOMAIN}.zendesk.com/api/v2/help_center/articles.json?per_page=100"
> zendesk-articles.json
while [ -n "$NEXT" ]; do
  resp=$(curl -s -u "${ZENDESK_USER}/token:${ZENDESK_API_TOKEN}" "$NEXT")
  echo "$resp" | jq -c '.articles[]' >> zendesk-articles.json
  NEXT=$(echo "$resp" | jq -r '.next_page // empty')
done
# Transform HTML body → markdown
import json, pathlib, markdownify, frontmatter
with open('zendesk-articles.json') as f:
    for line in f:
        a = json.loads(line)
        slug = a['html_url'].split('/')[-1]
        md = markdownify.markdownify(a['body'], heading_style='ATX')
        post = frontmatter.Post(md,
            title=a['title'],
            slug=f"how-to/{slug}",
            zendesk_id=a['id'],
            last_modified=a['updated_at'][:10],
            tags=a.get('label_names', []),
        )
        pathlib.Path(f"docs/imported/{slug}.md").write_text(frontmatter.dumps(post))

Recipe 5: Intercom Articles → markdown

# List articles
curl "https://api.intercom.io/articles?per_page=200" \
  -H "Authorization: Bearer $INTERCOM_TOKEN" \
  > intercom-articles.json

# Transform
python -c "
import json, pathlib, markdownify, frontmatter
data = json.load(open('intercom-articles.json'))
for a in data['data']:
    slug = a['url'].split('/')[-1] if a.get('url') else str(a['id'])
    md = markdownify.markdownify(a.get('body') or '', heading_style='ATX')
    post = frontmatter.Post(md, title=a['title'], slug=slug, intercom_id=a['id'])
    pathlib.Path(f'docs/imported/{slug}.md').write_text(frontmatter.dumps(post))
"

Recipe 6: Salesforce Knowledge → markdown

# Export via SOQL → CSV
sf data query --query "SELECT Id, Title, UrlName, Article_Body__c, LastModifiedDate FROM Knowledge__kav WHERE PublishStatus='Online'" \
  --result-format csv > sf-knowledge.csv

# Transform
python scripts/sf-to-md.py sf-knowledge.csv docs/imported/

Recipe 7: Attachment migration

# Confluence attachments
curl "https://${SITE}.atlassian.net/wiki/rest/api/content/${PAGE_ID}/child/attachment" \
  -u "${CONFLUENCE_USER}:${CONFLUENCE_API_TOKEN}" \
  | jq -r '.results[] | "\(.id) \(.title) \(._links.download)"' \
  | while read id title link; do
      curl -L "https://${SITE}.atlassian.net/wiki${link}" \
        -u "${CONFLUENCE_USER}:${CONFLUENCE_API_TOKEN}" \
        -o "docs/assets/${id}-${title}"
    done

# Rewrite references in MD
sed -i 's|/wiki/download/attachments/[0-9]*/\([^"]*\)|/assets/\1|g' docs/imported/*.md

Recipe 8: Build redirect map

# scripts/build-redirects.py
import json, pathlib, frontmatter
redirects = []
for p in pathlib.Path('docs/imported').rglob('*.md'):
    post = frontmatter.load(p)
    if 'old_url' in post:
        redirects.append({"from": post['old_url'], "to": f"/docs/{post['slug']}", "code": 301})
json.dump({"redirects": redirects}, open('redirects.json','w'), indent=2)
# Netlify _redirects equivalent
/old/path  /docs/how-to/x  301!

Recipe 9: Validate — link-check + page-count parity

# Link check imported
lychee --format json --output report.json docs/imported/

# Page count parity
ORIGINAL=$(jq '.results | length' confluence-pages.json)
IMPORTED=$(find docs/imported -name '*.md' | wc -l)
echo "Source: $ORIGINAL, Target: $IMPORTED"
[ "$ORIGINAL" -ne "$IMPORTED" ] && echo "MISMATCH"

Recipe 10: Visual spot-check via Playwright

// scripts/visual-check.js
const { chromium } = require('playwright');
(async () => {
  const browser = await chromium.launch();
  const ctx = await browser.newContext();
  for (const slug of process.argv.slice(2)) {
    const oldP = await ctx.newPage();
    const newP = await ctx.newPage();
    await oldP.goto(`https://old-kb.example.com/${slug}`);
    await newP.goto(`https://staging.docs.example.com/${slug}`);
    await oldP.screenshot({path: `diff/${slug}-old.png`});
    await newP.screenshot({path: `diff/${slug}-new.png`});
  }
  await browser.close();
})();

Recipe 11: Cutover redirects (platform-native)

// Vercel vercel.json
{"redirects":[{"source":"/old/path","destination":"/docs/how-to/x","permanent":true}]}
# Cloudflare Pages _redirects (same syntax as Netlify)
/old/path  /docs/how-to/x  301

Examples

Example 1: Notion → Docusaurus migration

Goal: 180 Notion pages → Docusaurus repo.

Steps:

  1. Design destination IA (taxonomy skill).
  2. Export via notion-to-md (Recipe 2).
  3. Rewrite Notion mentions / links to internal paths.
  4. Migrate attachments to static/img/.
  5. Build redirect map (Recipe 8) for Notion shared URLs.
  6. Lychee + page-count parity (Recipe 9).
  7. Visual spot-check 10 articles (Recipe 10).
  8. Soft launch (banner on Notion: "We've moved →"); DNS cutover; keep Notion read-only 30d.

Result: Clean Docusaurus site with redirects from Notion URLs.

Example 2: Confluence → MkDocs

Goal: 400 Confluence pages → MkDocs Material.

Steps:

  1. Export space → JSON (Recipe 3).
  2. Transform via html2text → md.
  3. Migrate attachments (Recipe 7).
  4. Sidebar nav (taxonomy skill output).
  5. Validate (Recipe 9).
  6. Cutover with redirects (Recipe 11).

Result: MkDocs site live; Confluence kept as historical archive.

Edge cases / gotchas

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.