Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created June 1, 2013 12:51
Show Gist options
  • Save jackfranklin/5690266 to your computer and use it in GitHub Desktop.
Save jackfranklin/5690266 to your computer and use it in GitHub Desktop.
require "csv"
CSV.foreach("data.csv", :headers => true) do |row|
slug = row["slug"]
type = row["type"] == "markdown" ? "md" : row["type"]
created_at = Time.at(row["created_on"].to_i)
filename = "#{created_at.strftime("%Y-%m-%d")}-#{slug}.#{type}"
title = row["title"]
body = row["body"]
author = "Jack Franklin"
jekyll_front_matter = []
jekyll_front_matter << "---"
jekyll_front_matter << "layout: post"
jekyll_front_matter << "title: \"#{title}\""
jekyll_front_matter << "---"
file_contents = "#{jekyll_front_matter.join("\n")}\n\n#{body}"
File.open("posts/#{filename}", "w") do |file|
file.puts file_contents
end
puts "Created posts/#{filename}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment