Using GitInfo

Hello - it’s been a while. Previously, I used a data parse technique to get git info into my page source.

 {{ $postgitinfo := (index $.Site.Data.postgitinfo .Slug ) }}
 {{ (print "<!-- LATEST GIT UPDATE: " $postgitinfo " -->") | safeHTML }}

Trying .GitInfo with Hugo v20,

 {{ $postgithash := .GitInfo.Hash }}
 {{ (print "<!-- LATEST GIT HASH: " $postgithash " -->") | safeHTML }}

… yields an error when building:

 ERROR 2017/04/08 10:19:45 partials/header.html template: partials/header.html:16:32: executing "partials/header.html" at <.GitInfo.Hash>: can't evaluate field Hash in type *gitmap.GitInfo

I wonder could anyone please point me in the right direction?

@RickCogley 久しぶり。

Do you have it enabled in your site config?

Hi @rdwatters, ご無沙汰さま!

Yes I do, and when hugo server renders the site, for pages that are not yet committed to the git repo, it throws an error related to that, so I think it’s working.

I tried something simpler, just doing {{ .GitInfo.Hash }} in my footer to see if it would display it.

It doesn’t, giving this error:

 ERROR 2017/04/08 10:36:58 partials/footer.html template: partials/footer.html:11:26: executing "partials/footer.html" at <.GitInfo.Hash>: can't evaluate field Hash in type *gitmap.GitInfo

I tried {{ .Site.GitInfo.Hash }}, {{ .Page.GitInfo.Hash }}, {{ .Hash }}, but, no dice.

My config.toml has:

 enableGitInfo = "true"

@rdwatters thanks for your help and time. I read various things and it looks like .GitInfo works on pages, and, updates .Page.Lastmod from the git commit date. I have not figured out how to use for my index file yet, so I guess that is why this “wasn’t working” for the page I was looking at - my top page.

But, it works on content pages. This is what I came up with as a little proof of concept:

 {{ if .IsPage }}<small class="gray"><em>Updated: {{ .Page.Lastmod }}, Version: {{ .GitInfo.AbbreviatedHash }}</em></
  small>{{ end }}

Hopefully it helps someone trying to implement this.

Awesome. Glad you figured it out.

As for the new use of, basically with v0.18, everything became a page, which means you now have access to all the page variables in your list/node pages. I appreciate this is confusing because we’re saying “everything is a page,” but when you put {{.IsPage}} on a list page, it returns false.

You can check it out here (excuse me if this is all old hat to you, but I’m not sure how long it’s been since you upgraded your Hugo version and haven’t seen you in the forums in a minute):

Note: If you want to continue using and don’t want the new everything-is-a-page features, you can disable some of this with the disableKinds configuration directive:


The URLs I’ve provided are actually for the new docs concept site I’ve been working on the for the past few months, so if you have any suggestions as a long-time Hugo user back on after a brief hiatus from the forums, etc, I’d certainly appreciate it :bow:

I decided to start doing short blog posts daily, and have got it fairly automated with scripts. I have a zsh function that creates a quick template and opens it in nvim. Then when the short post is ready, I commit and deploy. At first I was flirting with the idea of using something other than Hugo (the Horror!), but came to my senses and decided to try it all in Hugo, scripting it as much as possible to make it as frictionless as possible.

I found your site searching on some of the new functions I read about in the release notes, so I was referring to it to try to get them working.

I have not yet experimented with the “everything is a page” thing yet, but, will try it. From your comment I take it that it changed from no concept, to to I guess the idea is, if I have a ````` for any of my nodes, I can add metadata to the frontmatter as usual, and stop using

 {{ If .IsPage }}

That the idea?

Yes and then some. You can also add {{.Content}}, which comes in really handy. I used to use data file hacks to get head meta and descriptions to write to my “node” pages.

More importantly, just looked at your Git repo for RCC live. Referring to this line here:

Can you do me a solid and instead try the following and let me know if you get the same error in your terminal:

{{ if and (ne .Kind "taxonomy") (ne .Kind "taxonomyTerm") }}<small class="gray"><em>Updated: {{ .Lastmod }}, Version: {{ .GitInfo.AbbreviatedHash }}</em></small>{{ end }}

I’m wondering if it’s that you use partials/footer.html in your _default/terms.html, which isn’t actually checked into git because it’s made on the fly by Hugo…

Hi @rdwatters, ok, thanks, I’ll keep that in mind, about {{.Content}}.

As for the new code you suggest, I get this error now:

 ERROR 2017/04/08 11:53:16 partials/footer.html template: partials/footer.html:12:137: executing "partials/footer.html" at <.GitInfo.Abbreviated...>: can't evaluate field AbbreviatedHash in type *gitmap.GitInfo

… but, now at least the line renders on nodes. It does not show the sha for them, because they are built on the fly. I assume if I figure out that will be checked into git and let me get the version even for lists.

I think you’re right. Creating an for your sections (or even for your taxonomy terms pages and taxonomies) and checking them into git should remove that error, I believe.

That said, I feel like we can make that error more informative, to be sure…

1 Like

Thanks @rdwatters.

Do you happen to know of any public git repo that uses all the latest template types, like baseof.html and so on? Trying to figure out how to convert my new site to using the latest techniques.

The new docs concept definitely does:

As far as the newer i18n, I know that @bep is using it on his site:

More than that, unfortunately, I can’t point you to many more site repositories, but I’m sure they’re all over. Sorry, brother.

I should also mention a really cool feature that’s coming up with v20: custom output formats :smile:

Let me know if you need any help. I’ll be working on some Hugo-related stuff this weekend.

Yes, ok, Hugo-docs-concept looks great. I can get understanding from it. Thanks!

Love the output format idea. PDF would be useful in a few cases!

@rdwatters I used hugo-docs-concept repo and its content today to figure out how to restructure in the new block/define configuration. Not done yet so there’s still a lot broken, but basically it’s a better system than previous versions. Flexible.

1 Like

If you want bleading edge (as in Hugo 0.20), you can have a look at the latest commits at my repo:


Thanks @bep, I’ll take a look for sure. :slight_smile:

1 Like

Feedback, it works for partials still, but, in the templates using block and define, you cannot use this trick as a marker:

 {{ "<!-- ENTERING layouts/taxonomy/tag.html -->" | safeHTML }}
   template content
 {{ "<!-- LEAVING layouts/taxonomy/tag.html -->" | safeHTML }}

It chokes on it. Remove them and it’s fine.

Hi guys, ok, upgraded to v21-DEV when I heard about the v20 release. And, I’m getting some errors now, that I was not getting earlier. Some, like the one regarding Render are warnings so, the site still renders ok.

But, the footer is a problem. Something appears to be stricter now, with the .GitInfo and it no longer wants to render the sha.

The culprit might be the code @rdwatters provided below, I suspect.

This is the error below, and I hope you might have a moment to take a look.
Kind regards,

Ok, interesting: I had forgot to do git commit, and a couple of files were new and did not yet have sha’s. Once I committed, the footer renders and the ERRORs go away. I need to figure out how to make this a little more forgiving.

1 Like