Hubspot can be a great tool depending on the size/structure of your business, but it's not for everybody. If you find yourself wanting to move your blog off of Hubspot's COS, you've probably already found Hubspot's export documentation—and probably (like me) found the resulting data lacking.
(If you haven't done this, here's a spoiler: Hubspot exports each post as a separate html file, fully rendered complete with all of your template code. This isn't very helpful if you've built a new template somewhere else that you want to insert your old post content in.)
Here's how to migrate your blog
There's two pieces of info you need before you get started:
- Hubspot API key — You can get this here
- Hubspot blog ID — From your Hubspot dashboard, choose Content → Blog and choose the blog you want to export from the dropdown at the top. You'll find the blog's numeric ID in the URL. (The URL will have 2 numbers in it: you want the second, likely larger, number, as the first is your Hubspot account ID.)
Next, you should download this gist by clicking the "Download ZIP" button and unzip it somewhere. You should review the code here to make sure I'm not doing anything nefarious to your Hubspot data.
Then, to perform the export, you'll run the following commands in your shell (assuming you have a modern Ruby with Bundler installed):
$ cd path-to-gist
$ HUBSPOT_API_KEY=XXX HUBSPOT_BLOG_ID=YYY bundle exec ruby export_hubspot_blog_posts.rb
There should now be a
blog directory in there with a markdown file for each post you exported.
Customizing for your migration target
By default the script assumes you're trying to move to Github Pages or some other Jekyll-powered blog host. If you're trying to go somewhere else with your post content, you may find the script to be a good starting point. Inside the loop, you have easy access to all of the data you need to generate a corresponding new post within the new blog.
Moving posts to GitHub Pages/Jekyll
Just copy the
blog directory over to your blog repo. You'll probably want to make sure all these posts get put inside a layout by putting something like this in your
And that's it!
If you have ideas to make this better (or have found an error) please tweet us at @faradayio.