Skip to content

Commit

Permalink
YAML front matter fix, cleaned up slug generation, added tags and sto…
Browse files Browse the repository at this point in the history
…re some posterous information from the original post.
  • Loading branch information
simensen committed Nov 26, 2011
1 parent ddd5dbb commit 840b0c1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/jekyll/migrators/posterous.rb
Expand Up @@ -6,7 +6,7 @@
require 'uri' require 'uri'
require "json" require "json"


# ruby -r './lib/jekyll/migrators/posterous.rb' -e 'Jekyll::Posterous.process(email, pass, api_token, blog)' # ruby -r './lib/jekyll/migrators/posterous.rb' -e 'Jekyll::Posterous.process(email, pass, api_token, blog, tags_key)'
# You can find your api token in posterous api page - http://posterous.com/api . Click on any of the 'view token' links to see your token. # You can find your api token in posterous api page - http://posterous.com/api . Click on any of the 'view token' links to see your token.
# blog is optional, by default it is the primary one # blog is optional, by default it is the primary one


Expand All @@ -33,7 +33,7 @@ def self.fetch(uri_str, limit = 10)
end end
end end


def self.process(email, pass, api_token, blog = 'primary') def self.process(email, pass, api_token, blog = 'primary', tags_key = 'categories')
@email, @pass , @api_token = email, pass, api_token @email, @pass , @api_token = email, pass, api_token
FileUtils.mkdir_p "_posts" FileUtils.mkdir_p "_posts"


Expand All @@ -43,24 +43,32 @@ def self.process(email, pass, api_token, blog = 'primary')
while posts.any? while posts.any?
posts.each do |post| posts.each do |post|
title = post["title"] title = post["title"]
slug = title.gsub(/[^[:alnum:]]+/, '-').downcase slug = title.gsub(/[^[:alnum:]]+/, '-').gsub(/^-+|-+$/, '').downcase
posterous_slug = post["slug"]
date = Date.parse(post["display_date"]) date = Date.parse(post["display_date"])
content = post["body_html"] content = post["body_html"]
published = !post["is_private"] published = !post["is_private"]
name = "%02d-%02d-%02d-%s.html" % [date.year, date.month, date.day, slug] name = "%02d-%02d-%02d-%s.html" % [date.year, date.month, date.day, slug]
tags = []
post["tags"].each do |tag|
tags.push(tag["name"])
end


# Get the relevant fields as a hash, delete empty fields and convert # Get the relevant fields as a hash, delete empty fields and convert
# to YAML for the header # to YAML for the header
data = { data = {
'layout' => 'post', 'layout' => 'post',
'title' => title.to_s, 'title' => title.to_s,
'published' => published 'published' => published,
tags_key => tags,
'posterous_url' => post["full_url"],
'posterous_slug' => posterous_slug
}.delete_if { |k,v| v.nil? || v == ''}.to_yaml }.delete_if { |k,v| v.nil? || v == ''}.to_yaml


# Write out the data and content to file # Write out the data and content to file
File.open("_posts/#{name}", "w") do |f| File.open("_posts/#{name}", "w") do |f|
puts name puts name
f.puts name f.puts data
f.puts "---" f.puts "---"
f.puts content f.puts content
end end
Expand Down

0 comments on commit 840b0c1

Please sign in to comment.