Sha256: 57349a372b07d89359844bf3b3a7ac9f18c49009bbbec4fd5e8d5a47509b4f8c

Contents?: true

Size: 1.71 KB

Versions: 12

Compression:

Stored size: 1.71 KB

Contents

module JekyllImport
  module Importers
    class S9Y < Importer
      def self.specify_options(c)
        c.option 'source', '--source SOURCE', 'The URL of the S9Y RSS feed'
      end

      def self.validate(options)
        if options['source'].nil?
          abort "Missing mandatory option --source, e.g. --source \"http://blog.example.com/rss.php?version=2.0&all=1\""
        end
      end

      def self.require_deps
        JekyllImport.require_with_fallback(%w[
          open-uri
          rss
          fileutils
          safe_yaml
        ])
      end

      def self.process(options)
        source = options.fetch('source')

        FileUtils.mkdir_p("_posts")

        text = ''
        open(source) { |line| text = line.read }
        rss = ::RSS::Parser.parse(text)

        rss.items.each do |item|
          post_url = item.link.match('.*(/archives/.*)')[1]
          categories = item.categories.collect { |c| c.content }
          content = item.content_encoded.strip
          date = item.date
          slug = item.link.match('.*/archives/[0-9]+-(.*)\.html')[1]
          name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day,
                                                 slug]

          data = {
            'layout' => 'post',
            'title' => item.title,
            'categories' => categories,
            'permalink' => post_url,
            's9y_link' => item.link,
            'date' => item.date,
          }.delete_if { |k,v| v.nil? || v == '' }.to_yaml

          # Write out the data and content to file
          File.open("_posts/#{name}", "w") do |f|
            f.puts data
            f.puts "---"
            f.puts content
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
jekyll-import-0.12.0 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.11.0 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.10.0 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.9.0 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.8.0 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.7.1 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.7.0 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.6.0 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.5.3 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.5.2 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.5.1 lib/jekyll-import/importers/s9y.rb
jekyll-import-0.5.0 lib/jekyll-import/importers/s9y.rb