-
-
Save peet86/3c579e4843b8c9b6fcf7 to your computer and use it in GitHub Desktop.
Revisions
-
peet86 revised this gist
Oct 5, 2015 . No changes.There are no files selected for viewing
-
peet86 renamed this gist
Oct 5, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ # Basic Usage # ----------- # # ruby ./import_pyro_to_jekyll.rb feed_url # # where `feed_url` can have the following format: # -
peet86 revised this gist
Oct 5, 2015 . 1 changed file with 24 additions and 27 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,49 +1,47 @@ #!/usr/bin/env ruby # # Convert PyroCMS blog posts to jekyll posts # # Basic Usage # ----------- # # ./import.rb feed_url # # where `feed_url` can have the following format: # # http://{your.pyrocms.url}/blog/rss # # Requirements # ------------ # # * feedzirra: https://github.com/pauldix/feedzirra # * reverse_markdown: https://github.com/xijo/reverse_markdown # Notes # ----- # # * Make sure you made the changes in PyroCMS rss.php to show the full output of article in feeds. # * Plese note: the script converts PyroCMS blog category to jekyll and doesn't import pyrocms tags or comments. include RbConfig require 'rubygems' if CONFIG['host_os'].start_with? "darwin" require 'feedjira' require 'date' require 'optparse' require 'reverse_markdown' def parse_post_entries(feed, verbose) posts = [] feed.entries.each do |post| obj = Hash.new #p post file_name = post.published.strftime('%Y') + "-" + post.published.strftime('%m') + "-" + post.published.strftime('%d') + "-" + post.url.split('/').last + ".md" obj["file_name"] = file_name obj["title"] = post.title obj["creation_datetime"] = post.published obj["updated_datetime"] = post.updated obj["content"] = ReverseMarkdown.convert(post.summary, unknown_tags: :drop, github_flavored: true) obj["categories"] = post.categories.join(" ") posts.push(obj) end @@ -56,21 +54,20 @@ def write_posts(posts, verbose) total = posts.length, i = 1 posts.each do |post| file_name = "_posts/".concat(post["file_name"]) header = %{--- layout: post title: #{post["title"]} date: #{post["creation_datetime"]} published: true tags: #{post["categories"]} --- } File.open(file_name, "w+") {|f| f.write(header) f.write(post["content"]) f.close } if verbose puts " [#{i}/#{total[0]}] Written post #{file_name}" i += 1 @@ -81,17 +78,17 @@ def write_posts(posts, verbose) def main options = {} opt_parser = OptionParser.new do |opt| opt.banner = "Usage: ./import.rb FEED_URL [OPTIONS]" opt.separator "" opt.separator "Options" opt.on("-v", "--verbose", "Print out all.") do options[:verbose] = true end end opt_parser.parse! if ARGV[0] feed_url = ARGV.first else @@ -101,14 +98,14 @@ def main puts "Fetching feed #{feed_url}..." feed = Feedjira::Feed.fetch_and_parse(feed_url) puts "Parsing feed..." posts = parse_post_entries(feed, options[:verbose]) puts "Writing posts to _posts/..." write_posts(posts, options[:verbose]) puts "Done!" end main() -
Laurent Meyer revised this gist
Sep 5, 2015 . 1 changed file with 4 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,10 +22,10 @@ # * Make sure Blogger shows full output of article in feeds. # * Commenting on migrated articles will be set to false by default. include RbConfig require 'rubygems' if CONFIG['host_os'].start_with? "darwin" require 'feedjira' require 'date' require 'optparse' @@ -64,7 +64,6 @@ def write_posts(posts, verbose) comments: false categories: #{post["categories"]} --- } File.open(file_name, "w+") {|f| f.write(header) @@ -101,7 +100,7 @@ def main end puts "Fetching feed #{feed_url}..." feed = Feedjira::Feed.fetch_and_parse(feed_url) puts "Parsing feed..." posts = parse_post_entries(feed, options[:verbose]) @@ -112,4 +111,4 @@ def main puts "Done!" end main() -
bebraw revised this gist
Apr 24, 2012 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -42,6 +42,7 @@ def parse_post_entries(feed, verbose) obj["file_name"] = file_name obj["title"] = title obj["creation_datetime"] = created_datetime obj["updated_datetime"] = post.updated obj["content"] = content obj["categories"] = post.categories.join(" ") posts.push(obj) @@ -59,6 +60,7 @@ def write_posts(posts, verbose) layout: post title: #{post["title"]} date: #{post["creation_datetime"]} updated: #{post["updated_datetime"]} comments: false categories: #{post["categories"]} --- -
kennym revised this gist
Apr 23, 2012 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,17 +22,19 @@ # * Make sure Blogger shows full output of article in feeds. # * Commenting on migrated articles will be set to false by default. include Config require 'rubygems' if CONFIG['host_os'].start_with? "darwin" require 'feedzirra' require 'date' require 'optparse' def parse_post_entries(feed, verbose) posts = [] feed.entries.each do |post| obj = Hash.new created_datetime = post.updated creation_date = Date.parse(created_datetime.to_s) title = post.title file_name = creation_date.to_s + "-" + title.split(/ */).join("-").delete('\/') + ".html" content = post.content @@ -108,4 +110,4 @@ def main puts "Done!" end main() -
kennym revised this gist
Jul 30, 2011 . 1 changed file with 9 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ # Basic Usage # ----------- # # ./blogger_to_jekyll.rb feed_url # # where `feed_url` can have the following format: # @@ -16,6 +16,11 @@ # # * feedzirra: https://github.com/pauldix/feedzirra # # Notes # ----- # # * Make sure Blogger shows full output of article in feeds. # * Commenting on migrated articles will be set to false by default. require 'feedzirra' require 'date' @@ -36,6 +41,7 @@ def parse_post_entries(feed, verbose) obj["title"] = title obj["creation_datetime"] = created_datetime obj["content"] = content obj["categories"] = post.categories.join(" ") posts.push(obj) end return posts @@ -52,7 +58,7 @@ def write_posts(posts, verbose) title: #{post["title"]} date: #{post["creation_datetime"]} comments: false categories: #{post["categories"]} --- } @@ -72,7 +78,7 @@ def write_posts(posts, verbose) def main options = {} opt_parser = OptionParser.new do |opt| opt.banner = "Usage: ./blogger_to_jekyll.rb FEED_URL [OPTIONS]" opt.separator "" opt.separator "Options" -
kennym revised this gist
Jul 30, 2011 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -30,11 +30,12 @@ def parse_post_entries(feed, verbose) creation_date = Date.strptime(created_datetime.to_s, "%Y-%m-%d") title = post.title file_name = creation_date.to_s + "-" + title.split(/ */).join("-").delete('\/') + ".html" content = post.content obj["file_name"] = file_name obj["title"] = title obj["creation_datetime"] = created_datetime obj["content"] = content posts.push(obj) end return posts @@ -54,7 +55,7 @@ def write_posts(posts, verbose) categories: --- } File.open(file_name, "w+") {|f| f.write(header) f.write(post["content"]) -
kennym revised this gist
Jul 30, 2011 . 1 changed file with 0 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,13 +11,6 @@ # # http://{your_blog_name}.blogspot.com/feeds/posts/default # # Requirements # ------------ # -
kennym revised this gist
Jul 30, 2011 . 1 changed file with 47 additions and 26 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,47 +1,42 @@ #!/usr/bin/env ruby # # Convert blogger (blogspot) posts to jekyll posts # # Basic Usage # ----------- # # ruby blogger_to_jekyll.rb feed_url # # where `feed_url` can have the following format: # # http://{your_blog_name}.blogspot.com/feeds/posts/default # # Documentation # ------------- # # Command-line arguments: # -v # # # Requirements # ------------ # # * feedzirra: https://github.com/pauldix/feedzirra # require 'feedzirra' require 'date' require 'optparse' def parse_post_entries(feed, verbose) posts = [] feed.entries.each do |post| obj = Hash.new created_datetime = post.last_modified creation_date = Date.strptime(created_datetime.to_s, "%Y-%m-%d") title = post.title file_name = creation_date.to_s + "-" + title.split(/ */).join("-").delete('\/') + ".html" obj["file_name"] = file_name obj["title"] = title @@ -52,9 +47,10 @@ def parse_post_entries(feed) return posts end def write_posts(posts, verbose) Dir.mkdir("_posts") unless File.directory?("_posts") total = posts.length, i = 1 posts.each do |post| file_name = "_posts/".concat(post["file_name"]) header = %{--- @@ -71,20 +67,45 @@ def write_posts(posts) f.write(post["content"]) f.close } if verbose puts " [#{i}/#{total[0]}] Written post #{file_name}" i += 1 end end end def main options = {} opt_parser = OptionParser.new do |opt| opt.banner = "Usage: blogger_to_jekyll.rb FEED_URL [OPTIONS]" opt.separator "" opt.separator "Options" opt.on("-v", "--verbose", "Print out all.") do options[:verbose] = true end end opt_parser.parse! if ARGV[0] feed_url = ARGV.first else puts opt_parser exit() end puts "Fetching feed #{feed_url}..." feed = Feedzirra::Feed.fetch_and_parse(feed_url) puts "Parsing feed..." posts = parse_post_entries(feed, options[:verbose]) puts "Writing posts to _posts/..." write_posts(posts, options[:verbose]) puts "Done!" end main() -
kennym revised this gist
Jul 30, 2011 . 1 changed file with 13 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,10 @@ # Convert blogger (blogspot) posts to jekyll posts # # How to use # ---------- # # ruby blogger_to_jekyll.rb [feed_url] # # What it does # ------------ # @@ -9,29 +14,26 @@ # # --- # layout: post # title: #{post-title} # date: #{YYYY-mm-dd HH:MM} # comments: false # categories: # --- # # #{blog_post_content_in_html_format} # # 3) Write each file to a directory named `_posts` # # Requirements # ------------ # # * feedzirra: https://github.com/pauldix/feedzirra # require 'feedzirra' require 'date' def parse_post_entries(feed) posts = [] feed.entries.each do |post| @@ -72,12 +74,15 @@ def write_posts(posts) end end def main feed_url = ARGV.first puts "Fetching feed..." feed = Feedzirra::Feed.fetch_and_parse(feed_url) puts "Parsing feed..." posts = parse_post_entries(feed) puts "Writing posts..." write_posts(posts) end -
kennym revised this gist
Jul 30, 2011 . 1 changed file with 24 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,33 @@ # Convert blogger (blogspot) posts to jekyll posts # # What it does # ------------ # # 1) Fetches the blog's feed # 2) For each post create a file with name # "YYYY-MM-DD-{post-title}.html", with the following structure: # # --- # layout: post # title: {post-title} # date: {YYYY-mm-dd HH:MM} # comments: false # categories: # --- # # #{blog_post_content_in_html_format} # 3) Write each file to a directory named `_posts` # # Requirements # ------------ # # * feedzirra: https://github.com/pauldix/feedzirra # # How to use # ---------- # # ruby blogger_to_jekyll.rb [feed_url] # require 'feedzirra' require 'date' -
kennym created this gist
Jul 30, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ # Short overview: # 1) Fetch blogger feed # 2) For each post in feed # 1) create a file with name `YYYY-MM-DD-post-title.markdown`, with # the following structure: # # --- # layout: post # title: `post-title` # date: 2011-07-30 10:44 # comments: true # categories: # --- # # #{blog_post_content_in_markdown_format} # 3) Write each file to a directory `_posts` require 'feedzirra' require 'date' def parse_post_entries(feed) posts = [] feed.entries.each do |post| obj = Hash.new created_datetime = post.last_modified creation_date = Date.strptime(created_datetime.to_s, "%Y-%m-%d") title = post.title file_name = creation_date.to_s + "-" + title.split(/ */).join("-").delete('\/') + ".markdown" obj["file_name"] = file_name obj["title"] = title obj["creation_datetime"] = created_datetime obj["content"] = post.content posts.push(obj) end return posts end def write_posts(posts) Dir.mkdir("_posts") unless File.directory?("_posts") posts.each do |post| file_name = "_posts/".concat(post["file_name"]) header = %{--- layout: post title: #{post["title"]} date: #{post["creation_datetime"]} comments: false categories: --- %} File.open(file_name, "w+") {|f| f.write(header) f.write(post["content"]) f.close } end end def main(feed_url="http://feeds.feedburner.com/Kennys/dev/null?format=xml") puts "Fetching feed..." feed = Feedzirra::Feed.fetch_and_parse(feed_url) puts "Parsing feed..." posts = parse_post_entries(feed) puts "Writing posts..." write_posts(posts) end main()