Download the jekyll-git-data.rb
file to your Jekyll _plugins
directory.
The following variables can be used inside your liquid template.
{{ site.data['shorthash'] }}
-- git shortened hash{{ site.data['longhash'] }}
-- git hash{{ site.data['currentbranch'] }}
-- the current active branch
When the site is being generated by Jekyll, the plugin retrieves the Git data of the website source code and exposes it as a value in site.data
.
This feature is helpful when you want to show your current commit build data as a badge on your website. This makes use of the Github Badges.
For example, in your footer.html
:
<a href="//github.com/<user>/<repo>/commit/{{ site.data['longhash'] }}" rel="nofollow">
<img src="https://img.shields.io/badge/build-{{ site.data['shorthash'] }}-blue.svg?logo=github" alt="GitHub Commit">
</a>
This can also be used for cache busting. Appending your static resources (CSS, JS, etc.) by the git hash will force the browsers to reload the assets every time you deploy a new version of the site. Instead of generating a random number, you can use the git commit hash instead.
For example, in your default.html
:
<link rel="stylesheet" href="/css/main.css?{{ site.data['shorthash'] }}"/>