DocOps / asciidocsy-jekyll-theme

Jekyll/AsciiDoc port of Docsy theme for scalable technical documentation projects
https://asciidocsy.netlify.app/docs
Apache License 2.0
9 stars 9 forks source link

Git info variable #74

Open capsulecorplab opened 3 years ago

capsulecorplab commented 3 years ago

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?

briandominick commented 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.

briandominick commented 3 years ago

I got most of that command from here: https://gist.github.com/varemenos/e95c2e098e657c7688fd

briandominick commented 3 years ago

Oh I would also add _docs/_data/gitinfo.json to .gitignore -- we never want to commit built files, obviously.

briandominick commented 3 years ago

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 thansite.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.