How to import a Jekyll blog to Sanity?

32 replies
Last updated: Jan 28, 2026
To
user Y
or anyone who knows:Is there a recommended way to import a Jekyll blog to sanity? I just tried the “markdown-to-sanity” plugin, but it gave me an error.
AI Update

I found some helpful information about importing Jekyll blogs to Sanity! While there isn't a specific official "markdown-to-sanity" plugin in Sanity's documentation, there are several proven approaches you can use to migrate your Jekyll content.

The best solution is to use @portabletext/block-tools, which is designed specifically for converting HTML to Sanity's Portable Text format. Since Jekyll posts are markdown with YAML front matter, here's the workflow:

  1. Parse the markdown files - Use gray-matter to extract front matter (title, date, etc.) and the markdown body
  2. Convert markdown to HTML - Use a library like marked
  3. Convert HTML to Portable Text - Use @portabletext/block-tools

Here's a basic migration script structure:

import {JSDOM} from 'jsdom'
import {htmlToBlocks} from '@portabletext/block-tools'
import matter from 'gray-matter'
import {marked} from 'marked'
import fs from 'fs'

// Parse your Jekyll post
const fileContent = fs.readFileSync('your-post.md', 'utf-8')
const {data: frontMatter, content: markdown} = matter(fileContent)

// Convert markdown to HTML
const html = marked(markdown)

// Convert HTML to Portable Text blocks
const blocks = htmlToBlocks(html, blockContentSchema, {
  parseHtml: (html) => new JSDOM(html).window.document,
  rules: [
    // Add custom rules for images, code blocks, etc.
    {
      deserialize(node, next, block) {
        if (node.nodeName.toLowerCase() === 'img') {
          return block({
            _type: 'image',
            url: node.getAttribute('src'),
            alt: node.getAttribute('alt'),
          })
        }
        return undefined
      }
    }
  ]
})

Avoiding Import Errors

A common issue when running migration scripts is module import errors. The solution is to run your script using Sanity's CLI:

sanity exec path/to/your-migration-script.js --with-user-token

This lets you use ES6 import syntax and access Sanity's libraries directly without configuration headaches.

Handling Images

For images in your posts, you'll need to:

  1. Upload them to Sanity's asset pipeline using the client
  2. Replace URLs with Sanity asset references
  3. Use an in-memory cache to avoid re-uploading duplicates

The uploading assets efficiently guide covers this in detail.

Helpful Resources

About That Plugin Error

If you can share the specific error message you're getting with the "markdown-to-sanity" plugin, I can help troubleshoot it! It might be a versioning issue, configuration problem, or the plugin might be outdated. The @portabletext/block-tools approach above is the current recommended method and is actively maintained by the Sanity team.

Show original thread
32 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?