Class: Jekyll::GitHubLastModified::Tag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-github-last-modified/tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, path, tokens) ⇒ Tag

Returns a new instance of Tag.



9
10
11
12
# File 'lib/jekyll-github-last-modified/tag.rb', line 9

def initialize(tag_name, path, tokens)
  super
  @path = path
end

Instance Method Details

#render(context) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-github-last-modified/tag.rb', line 14

def render(context)
  github_path = Liquid::Template.parse(@path).render context
  github_token = context.registers[:site].config['github_token']
  github_repo = context.registers[:site].config['repository']
  headers = if github_token.nil? || github_token.empty? then {} else {Authorization: "token #{github_token.to_s}"} end
  uri = "https://api.github.com/repos/#{github_repo.to_s}/commits?path="+github_path.strip!
  response = RestClient.get(uri, headers)
  gitHubDetails = response.body
  return if gitHubDetails.nil? || gitHubDetails.empty?
  hash = JSON.parse(gitHubDetails)
  return if hash.nil? || hash.empty?
  github_date = hash[0]["commit"]["committer"]["date"]
  return if github_date.nil? || github_date.empty?
  DateTime.strptime(github_date,'%FT%TZ').to_s
end