- Create a
_plugins
directory in the root of your Jekyll site. - Place the ruby script into that directory. This can be done by either:
- Downloading the "raw" version of the
jekyll-git-status.rb
into that directory. - Cloning this gist into that directory as a submodule.
- Creating a new file, with the extension
.rb
in that path, and pasting in the content below.
- Downloading the "raw" version of the
- If you are already running
jekyll serve
orbundle exec jekyll serve
then stop and restart it.
This plugin adds some new "data" for your Jekyll site, which you can use as follows:
- Add content if this is part of a git repo:
{% if site.data.git.is_git_repo %}Some Content{% endif %}
- Add content if this repo is part of a git repo, but has had no commits:
{% if site.data.git.is_git_repo and not site.data.git.is_empty_repo %}Some Content{% endif %}
- Describe the last commit:
This is commit {{ site.data.git.last_hash_long }} AKA {{ site.data.git.last_hash }}.
It was tagged {{ site.data.git.commits_since_last_tag }} commits ago as {{ site.data.git.tag }}.
The first commit was on {{ site.data.git.first_commit_date }} at {{ site.data.git.first_commit_time }}.
{{ site.data.git.first_commit_tz }}
The last commit was on {{ site.data.git.last_commit_date }} at {{ site.data.git.last_commit_time }}.
{{ site.data.git.last_commit_tz }}
The content in this repo is (c) My Org Name {{ site.data.git.first_commit_year }}-{{ site.data.git.last_commit_year }}.
Sample output:
This is commit a1b2c3d4e5f6a7b8c9d0e1f2a3c4d5e6f7a8b9c0 AKA a1b2c3d.
It was tagged 0 commits ago as 0.0.1.
The first commit was on 1970-01-01 at 00:00:00 +0000.
The last commit was on 1971-01-01 at 00:00:00 +0000.
The content in this repo is (c) My Org Name 1970-1971.
As with all things metadata, values around first and last commit dates can be skewed or even purposefully falsified by incorrect clocks. DO NOT RELY ON THESE FOR ANYTHING SENSITIVE!
Released under the MIT license
This plugin for Jekyll is based loosely on three things;
Jekyll Version Plugin showed me how to check whether this was a valid Git Repo path, and some of the initial checks to make, however, by forcing it as a command, meant that I was basically asking the renderer to re-run the series of git commands each pass. Jekyll Git Hash Plugin showed me how to turn this set of commands into a blob of data I could add to my article. __git_ps1 showed me how to check more "git" things that I wanted to find.