Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git info variable #74

Open
capsulecorplab opened this issue Aug 16, 2021 · 4 comments
Open

Git info variable #74

capsulecorplab opened this issue Aug 16, 2021 · 4 comments

Comments

@capsulecorplab
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

@briandominick
Copy link
Contributor

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

@briandominick
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants