Created
April 6, 2011 02:15
-
-
Save danielvlopes/905011 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
articles = Article.find(:all) | |
articles.each do |article| | |
next if article.published_at.nil? | |
published_at = article.published_at | |
year = published_at.strftime('%Y') | |
month = published_at.strftime('%m') | |
day = published_at.strftime('%d') | |
published_at = "#{year}-#{month}-#{day}" | |
author = article.user.login | |
permalink = article.permalink | |
title = article.title | |
excerpt = article.excerpt | |
body = article.body | |
file_name = "#{published_at}-#{permalink}.md" | |
file_path = article.published_at.nil? ? "draft/#{file_name}" : "posts/#{file_name}" | |
fp = File.open(file_path, 'w') | |
fp.write(%" | |
title: \"#{title}\" | |
author: #{author} | |
date: #{year}/#{month}/#{day} | |
#{excerpt} | |
~ | |
#{body}") | |
fp.close | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment