Open capsulecorplab opened 3 years ago
There isn't a way to do this with Jekyll to my knowledge, but this would make a great plugin, so I might add it. I have definitely used this before, but I always ingest it before the build.
I think for now I would add a step to the build with a Bash command like:
git log -n 1 --pretty=format:'{%n "commit": "%H",%n "abbreviated_commit": "%h",%n "tree": "%T",%n "abbreviated_tree": "%t",%n "parent": "%P",%n "abbreviated_parent": "%p",%n "refs": "%D",%n "encoding": "%e",%n "subject": "%s",%n "sanitized_subject_line": "%f",%n "body": "%b",%n "commit_notes": "%N",%n "verification_flag": "%G?",%n "signer": "%GS",%n "signer_key": "%GK",%n "author": {%n "name": "%aN",%n "email": "%aE",%n "date": "%aD"%n },%n "commiter": {%n "name": "%cN",%n "email": "%cE",%n "date": "%cD"%n }%n},' > _docs/_data/gitinfo.json
Then the object will be available as site.data.gitinfo.commit
etc.
I got most of that command from here: https://gist.github.com/varemenos/e95c2e098e657c7688fd
Oh I would also add _docs/_data/gitinfo.json
to .gitignore
-- we never want to commit built files, obviously.
I just found the jekyll-github-metadata plugin, which gives you site.github.build_revision
variable, which renders the latest commit.
One thing that's awkward about attributes/variables with jekyll-asciidoc is that they don't cross those two scopes very well. If you set attributes in your AsciiDoc files, they won't be available as Jekyll/Liquid variables even on the same page template. Meanwhile, anything in the 'site' scope (other than
site.asciidoctor.attributes` is not available inside AsciiDoc files, unless you enable Liquid parsing in AsciiDoc, which I don't recommend, especially if you have Liquid code listings in your content, as we do.
I might try to modify jekyll-asciidoc in order to make the site
scope available as AsciiDoc attribute substitutions.
Hugo has a Git info variable that fetches the last commit associated with a contents page. Is it possible to do the same in Asciidocsy?