.Path when the page is backed by a file is deprecated and will be removed

I realize that my question has been asked before (here). I apologize for asking once more. My problem is only slightly different from the above linked one, but unfortunately I did not understand the suggested solution. I hope someone can give me a little more help…

So, here’s what I see when I run hugo --panicOnWarning:

Start building sites … 
hugo v0.108.0+extended linux/amd64 BuildDate=unknown
WARN 2023/01/04 12:15:19 .Path when the page is backed by a file is deprecated and will be removed in a future release. We plan to use Path for a canonical source path and you probably want to check the source is a file. To get the current behaviour, you can use a construct similar to the one below:

  {{ $path := "" }}
  {{ with .File }}
	{{ $path = .Path }}
  {{ else }}
	{{ $path = .Path }}
  {{ end }}
Error: Error building site: failed to render pages: render of "page" failed: "/home/me/Documents/MyGithub/Personal-Webpage/themes/hugo-academic/layouts/_default/baseof.html:4:3": execute of template failed: template: _default/single.html:4:3: executing "_default/single.html" at <partial "site_head" .>: error calling partial: "/home/me/Documents/MyGithub/Personal-Webpage/themes/hugo-academic/layouts/partials/site_head.html:16:51": execute of template failed: template: partials/site_head.html:16:51: executing "partials/site_head.html" at <.Path>: error calling Path: Warning trapped. Remove the --panicOnWarning flag to continue.
Total in 347 ms

Thus, I can tell that the problem is in themes/hugo-academic/layouts/partials/site_head.html:16:51. Below are the first 20 lines of this file:

<head>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="generator" content="Source Themes Academic {{ site.Data.academic.version }}">

  {{ $scr := .Scratch }}

  {{/* Attempt to load superuser. */}}
  {{ $superuser_name := "" }}
  {{ $superuser_username := "" }}
  {{ $superuser_role := "" }}
  {{ range first 1 (where (where site.Pages "Section" "authors") "Params.superuser" true) }}
    {{ $superuser_name = .Params.name }}
    {{ $superuser_username = path.Base (path.Split .Path).Dir }}
    {{ $superuser_role = .Params.role }}
  {{ end }}
  {{ $scr.Set "superuser_username" $superuser_username }}{{/* Set superuser globally for page_author.html. */}}
......

I do see .Path on line 16. Unfortunately I do not know how to implement the fix indicated on the previous linked thread. Could someone kindly show me how to do this? I’d be immensely grateful.

Also, is this fix bound to break each time I call hugo to rebuild my website?

Thank you in advance,
Bruce

Override the partial.

cp themes/hugo-academic/layouts/partials/site_head.html layouts/partials/site_head.html

Then edit the new file:

...
{{ range first 1 (where (where site.Pages "Section" "authors") "Params.superuser" true) }}
  {{ $path := "" }}
  {{ with .File }}
    {{ $path = .Path }}
  {{ else }}
    {{ $path = .Path }}
  {{ end }}
  {{ $superuser_name = .Params.name }}
  {{ $superuser_username = path.Base (path.Split $path).Dir }}
  {{ $superuser_role = .Params.role }}
{{ end }}
...

You should also raise an issue with the Wowchemy team:
https://github.com/wowchemy/wowchemy-hugo-themes/discussions

They also have an active Discord channel:
https://discord.com/invite/z8wNYzb

cc: @alcarazr

I just edited the code above.

@jmooring Thank you!! This worked perfectly!

After solving this one, I had to repeat the recipe for three other files (layouts/partials/widget_page.html, layouts/authors/list.html, layouts/index.json).

I will follow your suggestion about letting Wowchemy know about this.

Thank you so much!!
Bruce

1 Like

This was solved a while ago.

Update your Wowchemy installation instead of overriding old files.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.