Skip to content

Instantly share code, notes, and snippets.

@rokob
Created December 31, 2013 07:21
Show Gist options
  • Save rokob/8193628 to your computer and use it in GitHub Desktop.
Save rokob/8193628 to your computer and use it in GitHub Desktop.
module Jekyll
class Commit < Liquid::Tag
MATCHER = /\A(\S+)\Z/
def render(context)
markup = @markup.strip
page_file = "#{context.registers[:site].source}"
file_path = "#{context.environments.first["page"]["path"]}"
page_file += "/#{file_path}"
sha = `git log -n 1 --pretty=format:%H -- #{page_file}`
message = `git log -n 1 --pretty=format:%s -- #{page_file}`
history_url = "<a href='https://github.com/rokob/rokob.github.com/commits/source/"
history_url += file_path
history_url += "'>History</a>"
commit_url = "<span class='commit' title=\"#{message}\">"
if not markup.empty?
repo = markup.match(MATCHER)[1]
commit_url += "<a href=\"https://github.com/#{repo}/commit/#{sha}\""
commit_url += " title=\"#{message}\">#{sha[0...8]}</a>"
else
commit_url += "#{sha[0...8]}"
end
commit_url += "</span>"
history_url + " -- " + commit_url
end
end
end
Liquid::Template.register_tag('commit', Jekyll::Commit)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment