Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myabc/206284 to your computer and use it in GitHub Desktop.
Save myabc/206284 to your computer and use it in GitHub Desktop.
# To use:
# mkdir _posts
# script/runner migrate_articles_from_mephisto_markdown_files.rb
articles = Article.find(:all)
articles.each do |article|
published_at = "#{article.published_at.year}-#{article.published_at.month}-#{article.published_at.day}" unless article.published_at.nil?
author = article.user.login
permalink = article.permalink
title = article.title
excerpt = article.excerpt
body = article.body
fp = File.open("_posts/#{'draft-' if article.published_at.nil?}#{published_at}-#{permalink}.markdown", 'w')
fp.write(%"---
layout: post
title: \"#{title}\"
author: #{author}
---
#{excerpt}
#{body}")
fp.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment