Merge pull request #775 from metamatt/issue773
Address issue 773 (bugs preventing tumblr.rb from running)
This commit is contained in:
commit
b736676904
|
@ -34,7 +34,6 @@ 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
|
||||||
|
@ -43,11 +42,6 @@ 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)
|
||||||
|
@ -103,6 +97,7 @@ module Jekyll
|
||||||
date = Date.parse(post['date']).to_s
|
date = Date.parse(post['date']).to_s
|
||||||
title = Nokogiri::HTML(title).text
|
title = Nokogiri::HTML(title).text
|
||||||
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
|
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
|
||||||
|
slug = slug.slice(0..200) if slug.length > 200
|
||||||
{
|
{
|
||||||
:name => "#{date}-#{slug}.#{format}",
|
:name => "#{date}-#{slug}.#{format}",
|
||||||
:header => {
|
:header => {
|
||||||
|
@ -121,13 +116,12 @@ module Jekyll
|
||||||
# site/posts to get the correct permalink format.
|
# site/posts to get the correct permalink format.
|
||||||
def self.rewrite_urls_and_redirects(posts)
|
def self.rewrite_urls_and_redirects(posts)
|
||||||
site = Jekyll::Site.new(Jekyll.configuration({}))
|
site = Jekyll::Site.new(Jekyll.configuration({}))
|
||||||
dir = File.join(File.dirname(__FILE__), "..")
|
|
||||||
urls = Hash[posts.map { |post|
|
urls = Hash[posts.map { |post|
|
||||||
# Create an initial empty file for the post so that
|
# Create an initial empty file for the post so that
|
||||||
# we can instantiate a post object.
|
# we can instantiate a post object.
|
||||||
File.open("_posts/tumblr/#{post[:name]}", "w")
|
File.open("_posts/tumblr/#{post[:name]}", "w")
|
||||||
tumblr_url = URI.parse(post[:slug]).path
|
tumblr_url = URI.parse(post[:slug]).path
|
||||||
jekyll_url = Jekyll::Post.new(site, dir, "", "tumblr/" + post[:name]).url
|
jekyll_url = Jekyll::Post.new(site, Dir.pwd, "", "tumblr/" + post[:name]).url
|
||||||
redirect_dir = tumblr_url.sub(/\//, "") + "/"
|
redirect_dir = tumblr_url.sub(/\//, "") + "/"
|
||||||
FileUtils.mkdir_p redirect_dir
|
FileUtils.mkdir_p redirect_dir
|
||||||
File.open(redirect_dir + "index.html", "w") do |f|
|
File.open(redirect_dir + "index.html", "w") do |f|
|
||||||
|
|
Loading…
Reference in New Issue