Created
June 1, 2013 12:51
-
-
Save jackfranklin/5690266 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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