<commit_before>---
title: Commit Tag for Jekyll
published: March 22, 2013
excerpt: Liquid tag that links to the latest commit for your Jekyll site
tags: Git, Jekyll, Ruby
icon: github-alt
---

I've been touching up my site and I got to the footer, where I used to display the last time the site was generated, such as "generated March 22nd, 2013." I decided this was pretty tacky and removed it, but I did want to have something in the footer. Eventually I got the idea to instead put a short SHA1 hash of the latest commit for the site. It would link to the github page for said commit, and on hover of the link it would show the commit message.

After having seen previous plugin implementations, it seemed pretty simple enough. I quickly brought up the page for [rugged](https://github.com/libgit2/rugged), [libgit2's](http://libgit2.github.com/) ruby bindings.

> libgit2 is a portable, pure C implementation of the Git core methods provided as a re-entrant linkable library with a solid API, allowing you to write native speed custom Git applications in any language which supports C bindings.

The end result is the commit tag plugin which quite simply lets you insert a link to the latest commit of your site with the following properties:

* the link text is the short-form, 8-character truncated SHA1 hash to the commit pointed to by HEAD on the default branch, `source` in my case<commit_msg>note that I no longer do this on my site<commit_after>---
title: Commit Tag for Jekyll
published: March 22, 2013
excerpt: Liquid tag that links to the latest commit for your Jekyll site
tags: Git, Jekyll, Ruby
icon: github-alt
---

I've been touching up my site and I got to the footer, where I used to display the last time the site was generated, such as "generated March 22nd, 2013." I decided this was pretty tacky and removed it, but I did want to have something in the footer. Eventually I got the idea to instead put a short SHA1 hash of the latest commit for the site. It would link to the github page for said commit, and on hover of the link it would show the commit message.

Update
  ~ I have since [moved](/posts/the-switch-to-hakyll/) on to Hakyll and I stopped inserting the commit at the footer as this meant that I had to regenerate every page after every commit, as was the case in Jekyll as well. Instead, I have adopted a per-post commit tag and history link which I feel is a lot more meaningful and solves the aforementioned regeneration problem.

After having seen previous plugin implementations, it seemed pretty simple enough. I quickly brought up the page for [rugged](https://github.com/libgit2/rugged), [libgit2's](http://libgit2.github.com/) ruby bindings.

> libgit2 is a portable, pure C implementation of the Git core methods provided as a re-entrant linkable library with a solid API, allowing you to write native speed custom Git applications in any language which supports C bindings.

The end result is the commit tag plugin which quite simply lets you insert a link to the latest commit of your site with the following properties:

* the link text is the short-form, 8-character truncated SHA1 hash to the commit pointed to by HEAD on the default branch, `source` in my case
{'fraction_non_alphanumeric': 0.04729309271935283, 'fraction_numerical': 0.011823273179838207, 'mean_word_length': 4.2191558441558445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7478125', 'n_tokens_mistral': 852, 'n_tokens_neox': 784, 'n_words': 533}