Merge pull request #496 from dunsmoreb/issue/481

Truncate post slugs when importing from Tumblr.
This commit is contained in:
Parker Moore 2013-01-16 18:34:21 -08:00
commit 2e76edd837
1 changed files with 6 additions and 0 deletions

View File

@ -34,6 +34,7 @@ module Jekyll
post[:content] = html_to_markdown post[:content] post[:content] = html_to_markdown post[:content]
post[:content] = add_syntax_highlights post[:content] if add_highlights post[:content] = add_syntax_highlights post[:content] if add_highlights
end end
post[:name] = truncate_post_name post[:name] if post[:name].size > 255
File.open("_posts/tumblr/#{post[:name]}", "w") do |f| File.open("_posts/tumblr/#{post[:name]}", "w") do |f|
f.puts post[:header].to_yaml + "---\n" + post[:content] f.puts post[:header].to_yaml + "---\n" + post[:content]
end end
@ -42,6 +43,11 @@ module Jekyll
private 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 # Converts each type of Tumblr post to a hash with all required
# data for Jekyll. # data for Jekyll.
def self.post_to_hash(post, format) def self.post_to_hash(post, format)