Sha256: 38a6a76dfe1de6a7229e5a49129a097c8b8a852fb995d96c25d0d6913b517142

Contents?: true

Size: 788 Bytes

Versions: 2

Compression:

Stored size: 788 Bytes

Contents

require "csv"

module JekyllImport
  module CSV
    # Reads a csv with title, permalink, body, published_at, and filter.
    # It creates a post file for each row in the csv
    def self.process(options)
      file = options[:file] || "posts.csv"
      FileUtils.mkdir_p "_posts"
      posts = 0
      abort "Cannot find the file '#{file}'. Aborting." unless File.file?(file)
      ::CSV.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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-import-0.1.0.beta3 lib/jekyll/jekyll-import/csv.rb
jekyll-import-0.1.0.beta2 lib/jekyll/jekyll-import/csv.rb