Class: Jekyll::Commands::Kip

Inherits:
Command
  • Object
show all
Defined in:
lib/jekyll_kip.rb

Class Method Summary collapse

Class Method Details

._publish_to_kipalog(document) ⇒ Object



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
# File 'lib/jekyll_kip.rb', line 31

def _publish_to_kipalog(document)
  body = {
    title: document.data['title'],
    content: document.content,
    status: 'published',
    tag: (document.data['tags'] || []).join(',')
  }.to_json
  headers = {
    'Accept-Charset' => 'application/json',
    'X-Kipalog-Token' => _site.config['kipalog_api_token']
  }
  request = HTTParty.post(
    'http://kipalog.com/api/v1/post',
    body: body,
    headers: headers
  )

  response = JSON.parse(request.parsed_response, symbolize_names: true)

  if response[:status] != 200
    $stderr.puts response[:cause]
  else
    $stdout.puts "Post \"#{document.data['slug']}\" posted successfully"
  end
end

._siteObject



27
28
29
# File 'lib/jekyll_kip.rb', line 27

def _site
  @site ||= Site.new(configuration_from_options({})).tap(&:process)
end

.init_with_program(program) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/jekyll_kip.rb', line 9

def init_with_program(program)
  program.command(:kip) do |c|
    c.syntax "kip [SLUG]"
    c.description 'Cross-post blog to kip'

    c.action do |args, options|
      process(args, options)
    end
  end
end

.process(slugs, opts) ⇒ Object



20
21
22
23
24
25
# File 'lib/jekyll_kip.rb', line 20

def process(slugs, opts)
  _site.
    posts.docs.
    select { |doc| slugs.include?(doc['slug']) }.
    each { |doc| _publish_to_kipalog(doc) }
end