Class: JekyllImport::Importers::RSS
- Inherits:
-
JekyllImport::Importer
- Object
- JekyllImport::Importer
- JekyllImport::Importers::RSS
- Defined in:
- lib/jekyll-import/importers/rss.rb
Class Method Summary collapse
-
.process(options) ⇒ Object
Process the import.
- .require_deps ⇒ Object
- .specify_options(c) ⇒ Object
- .validate(options) ⇒ Object
Methods inherited from JekyllImport::Importer
inherited, run, stringify_keys, subclasses
Class Method Details
.process(options) ⇒ Object
Process the import.
source - a URL or a local file String.
Returns nothing.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/jekyll-import/importers/rss.rb', line 39 def self.process() source = .fetch('source') content = "" open(source) { |s| content = s.read } rss = ::RSS::Parser.parse(content, false) raise "There doesn't appear to be any RSS items at the source (#{source}) provided." unless rss rss.items.each do |item| formatted_date = item.date.strftime('%Y-%m-%d') post_name = item.title.split(%r{ |!|/|:|&|-|$|,}).map do |i| i.downcase if i != '' end.compact.join('-') name = "#{formatted_date}-#{post_name}" header = { 'layout' => 'post', 'title' => item.title } FileUtils.mkdir_p("_posts") File.open("_posts/#{name}.html", "w") do |f| f.puts header.to_yaml f.puts "---\n\n" f.puts item.description end end end |
.require_deps ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/jekyll-import/importers/rss.rb', line 24 def self.require_deps JekyllImport.require_with_fallback(%w[ rss/1.0 rss/2.0 open-uri fileutils safe_yaml ]) end |
.specify_options(c) ⇒ Object
14 15 16 |
# File 'lib/jekyll-import/importers/rss.rb', line 14 def self.(c) c.option 'source', '--source NAME', 'The RSS file or URL to import' end |
.validate(options) ⇒ Object
18 19 20 21 22 |
# File 'lib/jekyll-import/importers/rss.rb', line 18 def self.validate() if ['source'].nil? abort "Missing mandatory option --source." end end |