Andrew
Andrew

Reputation: 4338

Is there a way to include the git hash in a github pages site?

Github pages works by using the Markdown static site generator.

Is there a way to make it include the commit hash of the current gh-pages branch, so it is easy to check that a page has been updated, and that everyone is viewing the same version of the site?

Upvotes: 3

Views: 955

Answers (1)

VonC
VonC

Reputation: 1325017

This is not specific to GitHub page, and depends on the website generator you are using.
Github pages works with any static website generator you want.

For instance, Hugo would propose Git Info Variables, in order to get the last Git revision information for every content file.
Example:

    {{ with .GitInfo }} <!-- To enable this, put "enableGitInfo = true" in your site config.toml -->
        {{ $git := . }}
        {{ with $.Site.Params.source }}
            This page was created/modified in commit <a href="{{ .url }}/commit/{{- $git.Hash -}}">
            {{- $git.AbbreviatedHash -}}</a> "{{ $git.Subject }}" on <b>{{ dateFormat "2006-01-02" $git.AuthorDate }}</b>.
        {{ end }}
    {{ end }}

Regarding Jekyll, the engine behind GitHub Pages, the OP Andrew points out in the comments to this thread.

Suriyaa Kudo used in _layouts/default.html

<!-- build-commit-id: {{ site.github.build_revision }} -->

That, after declaring in _config.yml

repository: suriyaakudo/cdn.suriyaa.tk

You can see it in 26000+ files on GitHub.

Upvotes: 3

Related Questions