-
Notifications
You must be signed in to change notification settings - Fork 330
Fix Tumblr import #548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix Tumblr import #548
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,7 +83,7 @@ def write_post(post, use_markdown, add_highlights) | |
if use_markdown | ||
content = html_to_markdown content | ||
if add_highlights | ||
tumblr_url = URI.parse(post[:slug]).path | ||
tumblr_url = URI.parse(post[:url_with_slug]).path | ||
redirect_dir = tumblr_url.sub(%r!\/!, "") + "/" | ||
FileUtils.mkdir_p redirect_dir | ||
content = add_syntax_highlights(content, redirect_dir) | ||
|
@@ -162,16 +162,18 @@ def post_to_hash(post, format) | |
end | ||
{ | ||
:name => "#{date}-#{slug}.#{format}", | ||
:date => date, | ||
:header => { | ||
"layout" => "post", | ||
"title" => title, | ||
"date" => Time.parse(post["date"]).xmlschema, | ||
"tags" => (post["tags"] || []), | ||
"tumblr_url" => post["url-with-slug"], | ||
}, | ||
:content => content, | ||
:url => post["url"], | ||
:slug => post["url-with-slug"], | ||
:content => content, | ||
:url => post["url"], | ||
:slug => slug, | ||
:url_with_slug => post["url-with-slug"], | ||
} | ||
end | ||
|
||
|
@@ -209,11 +211,11 @@ def rewrite_urls_and_redirects(posts) | |
# Create an initial empty file for the post so that we can instantiate a post object. | ||
relative_path = "_posts/tumblr/#{post[:name]}" | ||
File.write(relative_path, "") | ||
tumblr_url = URI.parse(URI.encode(post[:slug])).path | ||
tumblr_url = URI.parse(URI::Parser.new.escape(post[:url_with_slug])).path | ||
jekyll_url = if Jekyll.const_defined? :Post | ||
Jekyll::Post.new(site, site.source, "", "tumblr/#{post[:name]}").url | ||
else | ||
Jekyll::Document.new(site.in_source_dir(relative_path), :site => site, :collection => site.posts).url | ||
"/" + Date.parse(post[:date]).to_s.tr("-", "/") + "/" + post[:slug] + ".html" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe these two changes output the files in different places than the current code does. Perhaps we should check this with a test to ensure a proper Jekyll site is output. I believe the goal was to write all the posts into the _posts directory so that they can be paginated and have all the goodies that come with documents in collections. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When run with the flag
When run without the flag The changes in my PR only apply to the latter file location. The former location still continues to generate as normal, and is not affected by my changes (that is handled by different code in a different method). It is true that the latter code does not output to the standard My PR does not change this overall behavior, it is the same as before; it was already being written to both My apologies for not writing a unit test for this. I ran into some difficulty with the development dependencies, because I don’t have MySQL, PostgreSQL, etc. installed (they are not necessary for the Tumblr importer) and I didn’t have time to look into that. As a result I was unable to get the unit tests running locally. Let me know what you think about my above explanation, and if you would prefer, I can try to look more into getting some test coverage for this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From my read of the code, In any event, if it's best to follow this path, then we shouldn't check for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry about the test dependencies. One thing I'd try is to comment out the dev dependencies you don't need, and to run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think that's right. In this case,
Very good point. I was worried there might be something like that. Do you have any suggestion for how to do it properly? I'm afraid I'm not familiar enough with this API.
I was hesitant to change that part of the branch because I didn't have an old version of Jekyll to test with. But I can do this if that's what you recommend. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, I was just revisiting this and wondered: could we use Jekyll to write the correct URL? It's definitely hardcoded here but why does it have to be? Jekyll provides diff --git jekyll-import.gemspec jekyll-import.gemspec
index 3e23db1..d46bd31 100644
--- jekyll-import.gemspec
+++ jekyll-import.gemspec
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
# importer dependencies:
# s.add_development_dependency("behance", "~> 0.3") # uses outdated dependencies
s.add_development_dependency("htmlentities", "~> 4.3")
- s.add_development_dependency("mysql2", "~> 0.3")
+ # s.add_development_dependency("mysql2", "~> 0.3")
s.add_development_dependency("open_uri_redirections", "~> 0.2")
s.add_development_dependency("pg", "~> 1.0")
s.add_development_dependency("rss", "~> 0.2")
diff --git lib/jekyll-import/importers/tumblr.rb lib/jekyll-import/importers/tumblr.rb
index b98b3e1..49f39d2 100644
--- lib/jekyll-import/importers/tumblr.rb
+++ lib/jekyll-import/importers/tumblr.rb
@@ -215,14 +215,20 @@ module JekyllImport
jekyll_url = if Jekyll.const_defined? :Post
Jekyll::Post.new(site, site.source, "", "tumblr/#{post[:name]}").url
else
- "/" + Date.parse(post[:date]).to_s.tr("-", "/") + "/" + post[:slug] + ".html"
+ Jekyll::Document.new(site.in_source_dir(relative_path), :site => site, :collection => site.posts).url
end
redirect_dir = tumblr_url.sub(%r!\/!, "") + "/"
- FileUtils.mkdir_p redirect_dir
+ FileUtils.mkdir_p(redirect_dir)
File.open(redirect_dir + "index.html", "w") do |f|
- f.puts "<html><head><link rel=\"canonical\" href=\"" \
- "#{jekyll_url}\"><meta http-equiv=\"refresh\" content=\"0; " \
- "url=#{jekyll_url}\"></head><body></body></html>"
+ f.puts <<~REDIRECT
+ ---
+ layout: null
+ ---
+ <html><head>
+ <link rel="canonical" href="{% link #{relative_path} %}">
+ <meta http-equiv="refresh" content="0; url={% link #{relative_path} %}">
+ </head><body></body></html>
+ REDIRECT
end
[tumblr_url, jekyll_url]
end] |
||
end | ||
redirect_dir = tumblr_url.sub(%r!\/!, "") + "/" | ||
FileUtils.mkdir_p redirect_dir | ||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is more correct, but it breaks the tests locally: