Skip to content
Browse files
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).
  • Loading branch information
metamatt committed Jan 22, 2013
1 parent 863643c commit fbc9d0c66397234ab85e03a55955602e0ce40356
Showing with 1 addition and 6 deletions.
  1. +1 −6 lib/jekyll/migrators/tumblr.rb
@@ -34,7 +34,6 @@ def self.process(url, format = "html", grab_images = false,
post[:content] = html_to_markdown post[:content]
post[:content] = add_syntax_highlights post[:content] if add_highlights
post[:name] = truncate_post_name post[:name] if post[:name].size > 255"_posts/tumblr/#{post[:name]}", "w") do |f|
f.puts post[:header].to_yaml + "---\n" + post[:content]
@@ -43,11 +42,6 @@ def self.process(url, format = "html", grab_images = false,


def self.truncate_post_name name
post = name.match(/^(.+)\.(.+)$/).captures
post[0][0..(-1 - post[1].size)] + post[1].size

# 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 @@ def self.post_to_hash(post, format)
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 => {

0 comments on commit fbc9d0c

Please sign in to comment.