Hugo

Page's .Hugo is deprecated as of 0.55.0

Hi, after upgrading to 0.55.0, I am getting this when I run hugo server:

 Building sites … WARN 2019/04/09 11:16:17 Page's .Hugo is deprecated and will be removed in a future release. Use the global hugo function.

… but I don’t find anything specific about this “global hugo function” in the docs or in github issues (I’m probably searching the wrong thing).

I assume this is talking about what you might put in your <head>, right? :

{{ printf "<!--Hugo Build Date: %s-->" .Hugo.BuildDate | safeHTML }}
{{ printf "<!--Hugo Commit Hash: %s-->" .Hugo.CommitHash | safeHTML }}
{{ .Hugo.Generator }}

Those are the only references I have to .Hugo in the site I got this error on. Can someone please point me at something that explains this? Thanks in advance.

4 Likes

Which template are those occurrences in?
It may be the case that in your particular template context, what looks like .Hugo is actually .Page.Hugo.

To give a concrete example, this is how I understand it

{{ .Page.Hugo.Generator }} <!-- deprecated -->
{{ $.Hugo.Generator }} <!-- okay -->
{{ hugo.Generator }} <!-- okay -->
4 Likes

thanks @zwbetz, this is my header partial being called by /layouts/index.html. Tried a couple things and just replacing .Hugo in my original example with hugo seems to work:

<!-- Hugo info -->
{{ printf "<!--Hugo Build Date: %s-->" hugo.BuildDate | safeHTML }}
{{ printf "<!--Hugo Commit Hash: %s-->" hugo.CommitHash | safeHTML }}
{{ hugo.Generator }}

After that change, no more build WARN and I still see the expected strings in html source:

<!--Hugo Build Date: 2019-04-08T17:03:33Z-->
<!--Hugo Commit Hash: 4333cc77f-->
<meta name="generator" content="Hugo 0.55.0" />
6 Likes

You are very skilled! But some people reading this may not understand what has been done.

Would it be possible to explain so a broader audience can benefit? :slight_smile:

2 Likes

Even s/\$?\.H/h/ and s/\$?\.Site/site/.

That wasn’t even a real regex & I was just typing quickly, so I’ll amend.

This appears to be completely undocumented, I just checked the docs for .Hugo. Doesn’t appear to be in the release notes either.

It isn’t yet, I don’t think.

Fantastic. This has brought an end to a confused 20 mins, when the documented code generates an error… :slight_smile: https://gohugo.io/variables/hugo/

2 Likes

2 posts were split to a new topic: Function “Hugo” not defined

Docs still not updated. https://gohugo.io/variables/hugo/

Feel free to make a PR :slightly_smiling_face: