Class: JekyllDeployShosetsu::Deployers::Kakuyomu

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-deploy-shosetsu/deployers/kakuyomu.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent: KakuyomuAgent.new) ⇒ Kakuyomu

Returns a new instance of Kakuyomu.



6
7
8
# File 'lib/jekyll-deploy-shosetsu/deployers/kakuyomu.rb', line 6

def initialize(agent: KakuyomuAgent.new)
  @agent = agent
end

Instance Attribute Details

#agentObject (readonly)

Returns the value of attribute agent.



4
5
6
# File 'lib/jekyll-deploy-shosetsu/deployers/kakuyomu.rb', line 4

def agent
  @agent
end

Instance Method Details

#deploy(site) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jekyll-deploy-shosetsu/deployers/kakuyomu.rb', line 10

def deploy(site)
  email    = site.config['kakuyomu']['email']
  password = site.config['kakuyomu']['password']
  agent.login!(email: email, password: password)

  work_id = site.config['kakuyomu']['work_id']

  site.posts.docs.each do |post|
    kakuyomu_config = post['kakuyomu'] || {}
    next if kakuyomu_config['ignore']

    post.output = Jekyll::Renderer.new(site, post).run

    if kakuyomu_config['url']
      episode_id = KakuyomuAgent::UrlHelper.extract_episode_id(kakuyomu_config['url'])
      url        = agent.update_episode(work_id: work_id, episode_id: episode_id, title: post['title'], body: post.output, date: post.date)
      Jekyll.logger.info 'Updated:', "#{post.basename} #{url}"
    else
      url = agent.create_episode(work_id: work_id, title: post['title'], body: post.output, date: post.date)
      Jekyll.logger.info 'Created:', "#{post.basename} #{url}"
      Util.append_yaml_front_matter post.path, <<~YAML
        kakuyomu:
          url: #{url}
      YAML
    end
  end
end