Could we add versioning/themes’ or sites’ hashes for cases where git
is used? It could be just variables that are detected automatically prior to the rendering, or a function returning the current (commit) hash for the site/theme. The default call would return the current hash for the project, and theme
would do the same for the theme.
To avoid bulky git2-rs
and its dependencies, we could just check HEAD
/refs/$BRANCH
files in .git/
manually. Hardcoded common branch names sound like the trickiest part (if we forget about dirty
states).
Maybe later we could get fancy and also check tags, but I’m not sure how many keep tagging their themes if no package infra is involved (and that’s the case for PWAs, mostly).
Implemented head hash but load_data()
does not work with variables:
{%- if config.extra.footer.hash == true %}
{%- set head_branch = load_data(path=".git/HEAD") | replace(from="ref: ", to="") %}
{#- load_data(path=head_branch_path)v is not working #}
{%- if head_branch is containing("refs/heads/trunk") %}
{%- set_global hash = load_data(path=".git/refs/heads/trunk") %}
{%- elif head_branch is containing("refs/heads/main") %}
{%- set_global hash = load_data(path=".git/refs/heads/main") %}
{%- elif head_branch is containing("refs/heads/master") %}
{%- set_global hash = load_data(path=".git/refs/heads/master") %}
{% else %}
{% if get_env(name="GITHUB_SHA", default="NONE") != "NONE" %}
{%- set_global hash = get_env(name="GITHUB_SHA") %}
{% elif get_env(name="COMMIT_REF", default="NONE") != "NONE" %}
{%- set_global hash = get_env(name="COMMIT_REF") %}
{% elif get_env(name="CI_COMMIT_SHA", default="NONE") != "NONE" %}
{%- set_global hash = get_env(name="CI_COMMIT_SHA") %}
{% endif %}
{%- endif %}
{%- endif %}
@keats is this a bug?