class Jekyll::GitHubLastModified::Tag

Public Class Methods

new(tag_name, path, tokens) click to toggle source
Calls superclass method
# File lib/jekyll-github-last-modified/tag.rb, line 9
def initialize(tag_name, path, tokens)
  super
  @path = path
end

Public Instance Methods

render(context) click to toggle source
# 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