Skip to content

Instantly share code, notes, and snippets.

@danielvlopes
Created April 6, 2011 02:15
Show Gist options
  • Save danielvlopes/905011 to your computer and use it in GitHub Desktop.
Save danielvlopes/905011 to your computer and use it in GitHub Desktop.
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