Caves Pommery à Reims

I’ve just finished migrating 10 years of blogging from Publify to Medium. If you’re wondering, I’ll keep this blog online and updated, but I wanted to profit from the community and awesome UI Medium brings since I’ve never been able to do a proper design.

In this post, I’ll explain how you can migrate any blog to Medium since only Wordpress is supported so far.

To migrate your blog to Medium, you need:

  • Some dev and UNIX skills.
  • A blog.
  • A Medium account and a publication.
  • A Medium integration API key.
  • To ask Medium to remove the publishing API rate limit on your publication.

Installing medium-cli

There are many Medium SDKs around but most of them are incomplete and won’t allow you to publish in publications, but there’s a workaround. I’ve chosen to rely on medium-cli, a NPM command line interface that does the trick.

$ (sudo) npm install (-g) medium-cli

Medium-cli does not allow to push to a publication so we’ll have to patch it a bit to make it work. Edit the lib/medium.js file and replace line 38 with:

.post(uri + ‘publications/’ + userId + ‘/posts’)

Since medium-cli also cleans unwanted arguments, we’ll have to add 2 lines at the end of the clean() function, lines 61–62.

publishedAt: post.publishedAt,
notifyFollowers: post.notifyFollowers

These are 2 important options:

  • publishedAt is a non documented API feature that allows to back date your old posts.
  • notifyFollowers will prevent Medium from spamming your followers will all your new publications.

Setting up medium-cli to post to your publication

To post to Medium with medium-cli, you need:

  • Your Medium user id.
  • Your Medium publication id.

We’ll get it using the API with some curl foo.

First, get your own information:

$ curl -H “Authorization: Bearer yourmediumapikeyyoujustgenerated”
{“data”:{“id”:”1234567890",”username”:”fdevillamil”,”name”:”Fred de Villamil ✌︎”,”url”:”","imageUrl":"*IKwA8UN-sM_AoqVj.jpg"}}

Now, get your publication id

$ curl -H “Authorization: Bearer yourmediumapikeyyoujustgenerated”
{“data”:[{“id”:”987654321",”name”:”Fred Thoughts”,”description”:”Fred Thoughts on Startups, UX and Co”,”url”:”","imageUrl":"*EqoJ-xFhWa4dE-2i1jGnkg.png"}]}

You’re almost done. Now, create a medium-cli blog and configure it with your API key.

$ medium create myblog
$ medium login
$ rm -rf myblog/articles/*

Edit your ~/.netrc file as the following:

 token yourmediumapikeyyoujustgenerated
 userId 987654321

Here we are (born to be king) we can now export the content of your blog.

Export your blog content

There are many ways to export your blog content. If you don’t have a database access, you can crawl it with any script using the readitlater library.

For my Publify blog, I’ve written a rake task.

desc “Migrate to medium”
task :mediumise => :environment do
 require ‘article’
dump = “/path-to/newblog/”
Article.published.where(“id > 7079”).order(:published_at).each do |article|
 if File.exists? “#{dump}/{}-#{article.permalink}”
 Dir.mkdir “#{dump}/#{}-#{article.permalink}”
 open(“#{dump}/#{}-#{article.permalink}/”, ‘w’) do |f|
 f.puts “ — -”
 f.puts “title: \”#{article.title}\””
 f.puts “tags: \”#{article.tags[0,2].map { |tag| tag.display_name }.join(“, “)}\””
 f.puts “canonicalUrl:{article.permalink}.html”
 f.puts “publishStatus: public”
 f.puts “license: cc-40-by-nc-sa”
 f.puts “publishedAt: ‘#{article.published_at.to_time.iso8601}’”
 f.puts “notifyFollowers: false”
 f.puts “ — -”
 f.puts “”
 f.puts article.html(:body)
 f.puts “”
 f.puts article.html(:extended)
 f.puts “”
 f.puts “Original article published on <a href=’{article.permalink}.html’>#{article.title}</a>”

Nothing really complicated indeed. Whatever your solution, export in your myblog directory. Then

$ mkdir archives
$ mkdir failed
$ cd myblog
for i in $(ls | egrep -v ^articles | sort -n | head -n 10); do 
mv $i articles
foo=$(medium publish | grep Done)
if [ -z “$foo” ]; then
 echo failed: $i
 mv articles/$i ../failed
 echo OK: $i
 mv articles/$i ../archives/

That’s all folks! Hope it will help you while you’re waiting for Medium to provide an easier way to do it.

Perry the Platypus wants you to subscribe now! Even if you don't visit my site on a regular basis, you can get the latest posts delivered to you for free via Email: