We had a great talk last week by Brian Rinaldi, who reviewed some of the ways to migrate from Wordpress and other CMS’s into a Git-based JAMstack site. Most of the migrations I’ve done have come from other CMSs, so I thought I’d outline the process here.

My process is primarily manual and I’m sure there’s room to make this easier, but the manual steps have helped me make sure I’m transferring clean content.

Before you begin, you need to have your content model in place so you understand what the top-level collections are, and what your fields look like.

The overall process is just three steps:

1) Output your content into templates from your existing CMS that are formatted much like Markdown documents.

2) Run that output through an HTML to Markdown converter.

3) Convert the resulting content into individual files.

1) Output content to templates

This part will require some thought. What we’re doing is creating a blank HTML template and looping through a section of our content. However your content is broken down (posts/pages/collections/sections) you’ll create one of these templates for each section. If you have a great number of entries in any given section, you may need to break it into smaller chunks and output each separately.

the example is for YAML, but can be adjusted for whatever format you need, TOML, or JSON

You can see below that within my for-loop, I’m merely outputting a Markdown document with front matter; with one exception.

For our export, we’ll change one thing. We’ll swap out the opening three dashes --- with a symbol @@@. This will be important later, because we’ll use that symbol to demarcate the beginning of each document.

2) Run through a HTML to Markdown converter

Once you render that page in your browser, view source. Now you’ll want to get that HTML into Markdown. I use Dom Christie’s excellent “to-markdown” for this process. If you’re going to be using it a lot, you can fork it and run your own version, but it’s running at domchristie.github.io/to-markdown/ and you can use it there as well.

Note: Be sure you check the “Github Flavored Markdown” box

Copy your HTML content and paste it into the HTML box on the left, and on the right you’ll find your rendered Markdown content.

Copy that content and paste it into a text editor (I use Sublime for this because it can handle large files and has good Regex). This is your opportunity to scan your content and clean it up to make sure you’ve output it correctly. It can sometimes take trial-and-error to get the fields’ formatting and data right.

One thing that the Markdown converter doesn’t do well is to convert spaces, which you may use for YAML objects, like this:

image:
- path: "/path/image.jpg"
caption: "caption copy here"

I output with dollar signs (or use any symbol that makes sense for your content) with spaces, like this:

image:
$$- path: "/path/image.jpg"
$$$$caption: "caption copy here"

And then replace the dollar signs in mass once you’ve copied over to the text editor.

This should output all the entries to documents in the same folder that look like some-title.md. Here’s a Gist with a similar example: gist

You can also change _slug in my example to date if you need your documents to be date-based for something like Jekyll posts.

That’s the process. It will most likely require some trial-and-error, and a fair amount of patience, but once you’re in Markdown heaven you’ll have content that is readable, easy to manipulate, and portable from system to system.

If you want to discuss this process, you’re welcome to reach out on Twitter, or join our Slack.