Module: Jekyll::CSV

Defined in:
lib/jekyll/migrators/csv.rb

Class Method Summary collapse

Class Method Details

.process(file = "posts.csv") ⇒ Object

Reads a csv with title, permalink, body, published_at, and filter. It creates a post file for each row in the csv



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jekyll/migrators/csv.rb', line 5

def self.process(file = "posts.csv")
  FileUtils.mkdir_p "_posts"
  posts = 0
  FasterCSV.foreach(file) do |row|
    next if row[0] == "title"
    posts += 1
    name = row[3].split(" ")[0]+"-"+row[1]+(row[4] =~ /markdown/ ? ".markdown" : ".textile")
    File.open("_posts/#{name}", "w") do |f|
      f.puts <<-HEADER
---
layout: post
title: #{row[0]}
---

      HEADER
      f.puts row[2]
    end
  end
  "Created #{posts} posts!"
end