From 863643c7e8080c73a7968caabfc9c7e9b18c6b95 Mon Sep 17 00:00:00 2001 From: Matt Ginzton Date: Tue, 22 Jan 2013 09:27:17 -0800 Subject: [PATCH 1/3] Look for _posts directory relative to cwd, not relative to tumblr.rb. That's where we put it earlier, so that's where we'll find it now. This addresses part of issue #773 (subissue 3). --- lib/jekyll/migrators/tumblr.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/jekyll/migrators/tumblr.rb b/lib/jekyll/migrators/tumblr.rb index 8b717d5d..b44c0140 100644 --- a/lib/jekyll/migrators/tumblr.rb +++ b/lib/jekyll/migrators/tumblr.rb @@ -121,13 +121,12 @@ module Jekyll # site/posts to get the correct permalink format. def self.rewrite_urls_and_redirects(posts) site = Jekyll::Site.new(Jekyll.configuration({})) - dir = File.join(File.dirname(__FILE__), "..") urls = Hash[posts.map { |post| # Create an initial empty file for the post so that # we can instantiate a post object. File.open("_posts/tumblr/#{post[:name]}", "w") tumblr_url = URI.parse(post[:slug]).path - jekyll_url = Jekyll::Post.new(site, dir, "", "tumblr/" + post[:name]).url + jekyll_url = Jekyll::Post.new(site, ".", "", "tumblr/" + post[:name]).url redirect_dir = tumblr_url.sub(/\//, "") + "/" FileUtils.mkdir_p redirect_dir File.open(redirect_dir + "index.html", "w") do |f| From fbc9d0c66397234ab85e03a55955602e0ce40356 Mon Sep 17 00:00:00 2001 From: Matt Ginzton Date: Tue, 22 Jan 2013 10:07:19 -0800 Subject: [PATCH 2/3] Fix truncation of overly long post names. Delete the old truncate_post_name; it was called too late (if url rewriting is enabled which it is by default), didn't run (it tried to use + to concat a Fixnum onto a String), and even with those problems fixed, didn't actually shorten the string enough to use as a pathname. Instead, apply simple string truncation at the point we generate the slug, which is used in the filename and is the part that could be unboundedly long. I arbitrarily chose 200 as the maximum length; even shorter might be better (really long slugs are just visually ugly); it might also be nicer to truncate at a hyphen boundary. This fixes the rest of issue #773 (subissue 4). --- lib/jekyll/migrators/tumblr.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/jekyll/migrators/tumblr.rb b/lib/jekyll/migrators/tumblr.rb index b44c0140..bbb7ae16 100644 --- a/lib/jekyll/migrators/tumblr.rb +++ b/lib/jekyll/migrators/tumblr.rb @@ -34,7 +34,6 @@ module Jekyll post[:content] = html_to_markdown post[:content] post[:content] = add_syntax_highlights post[:content] if add_highlights end - post[:name] = truncate_post_name post[:name] if post[:name].size > 255 File.open("_posts/tumblr/#{post[:name]}", "w") do |f| f.puts post[:header].to_yaml + "---\n" + post[:content] end @@ -43,11 +42,6 @@ module Jekyll private - def self.truncate_post_name name - post = name.match(/^(.+)\.(.+)$/).captures - post[0][0..(-1 - post[1].size)] + post[1].size - end - # Converts each type of Tumblr post to a hash with all required # data for Jekyll. def self.post_to_hash(post, format) @@ -103,6 +97,7 @@ module Jekyll date = Date.parse(post['date']).to_s title = Nokogiri::HTML(title).text slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '') + slug = slug.slice(0..200) if slug.length > 200 { :name => "#{date}-#{slug}.#{format}", :header => { From c95c5e3b7dc5b9fba11b05bd7410e563c64e28d2 Mon Sep 17 00:00:00 2001 From: Matt Ginzton Date: Fri, 25 Jan 2013 15:57:45 -0800 Subject: [PATCH 3/3] Use Dir.pwd instead of "." as the source argument to Post.new, since this has historically supplied an absolute path in this call. --- lib/jekyll/migrators/tumblr.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/jekyll/migrators/tumblr.rb b/lib/jekyll/migrators/tumblr.rb index bbb7ae16..4a1e19d7 100644 --- a/lib/jekyll/migrators/tumblr.rb +++ b/lib/jekyll/migrators/tumblr.rb @@ -121,7 +121,7 @@ module Jekyll # we can instantiate a post object. File.open("_posts/tumblr/#{post[:name]}", "w") tumblr_url = URI.parse(post[:slug]).path - jekyll_url = Jekyll::Post.new(site, ".", "", "tumblr/" + post[:name]).url + jekyll_url = Jekyll::Post.new(site, Dir.pwd, "", "tumblr/" + post[:name]).url redirect_dir = tumblr_url.sub(/\//, "") + "/" FileUtils.mkdir_p redirect_dir File.open(redirect_dir + "index.html", "w") do |f|