Module: Skiptorium

Defined in:
lib/skiptorium.rb,
lib/skiptorium/config.rb,
lib/skiptorium/article.rb,
lib/skiptorium/version.rb,
lib/skiptorium/rss/source.rb,
lib/skiptorium/base_source.rb,
lib/skiptorium/dev_to/source.rb,
lib/skiptorium/base_destination.rb,
lib/skiptorium/local/destination.rb,
lib/skiptorium/dev_to/destination.rb,
lib/skiptorium/blogger/destination.rb,
lib/skiptorium/hashnode/destination.rb,
lib/skiptorium/github_pages/destination.rb

Defined Under Namespace

Modules: Blogger, DevTo, GitHubPages, Hashnode, Local, RSS Classes: Article, BaseDestination, BaseSource, Config, Error

Constant Summary collapse

VERSION =
'0.1.1'

Class Method Summary collapse

Class Method Details

.build_destination(dest_config) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/skiptorium.rb', line 72

def self.build_destination(dest_config)
  case dest_config['type']
  when 'dev_to' then DevTo::Destination.new(dest_config)
  when 'hashnode' then Hashnode::Destination.new(dest_config)
  when 'github_pages' then GitHubPages::Destination.new(dest_config)
  when 'blogger' then Blogger::Destination.new(dest_config)
  when 'local' then Local::Destination.new(dest_config)
  #else raise Error, "Unknown destination type: #{dest_config['type']}"
  else nil
  end
end

.build_source(source_config) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/skiptorium.rb', line 64

def self.build_source(source_config)
  case source_config['type']
  when 'dev_to' then DevTo::Source.new(source_config)
  when 'rss' then RSS::Source.new(source_config)
  else raise Error, "Unknown source type: #{source_config['type']}"
  end
end

.run(config_path, dry_run: false, verbose: false) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/skiptorium.rb', line 25

def self.run(config_path, dry_run: false, verbose: false)
  config = Config.load(config_path)

  source = build_source(config.source)
  destinations = config.destinations.map { |d| build_destination(d) }.compact

  articles = source.fetch_latest

  if verbose
    puts "Found #{articles.length} article(s) from source:"
    articles.each do |article|
      puts "  => #{article.title}"
    end
  end

  destinations.each do |destination|
    puts "[SCAN] #{destination.class.name}"

    to_publish = articles.take_while do |a|
      if !destination.exists?(a)
        puts "  [TAKE] Article '#{a.title}'"
        true
      else
        puts "  [SKIP] Article '#{a.title}' already exists in #{destination.class.name}"
        false
      end
    end

    to_publish.sort_by(&:published_at).each do |article|
      puts "  [PUBLISH] Publishing '#{article.title}' to #{destination.class.name}"
      if dry_run
        puts '    (dry-run mode, not actually publishing)'
      else
        destination.publish(article)
      end
    end
  end
end