Yukuro / hugo-theme-shell

Hugo Shell theme : Terminal-like theme with selectable color schemes.
https://hugo-theme-shell-example.vercel.app/
MIT License
327 stars 109 forks source link

WARN .File.BaseFileName on zero object. Wrap it in if or with: {{ wit… #38

Closed nonumeros closed 1 year ago

nonumeros commented 2 years ago

…h .File }}{{ .BaseFileName }}{{ end }}

nonumeros commented 2 years ago

I have to admit I don't understand most of the site code, but As I follow it, the following chunk takes care of the left-most part of th e navbar

    {{ $lengthToCut := mul -1 (add (len .File.BaseFileName) 1) }}

If one were to say, how do I actually get rid of this pesky warning message .File.BaseFileName on zero object. Wrap it in if or with: {{ with .File }}{{ .BaseFileName }}{{ end }}

and Say, let's replace .File.BaseFileName with .Path since it would redirect to .RelPermalink it all seems at first as if it works. Unless of course, say, a file is further created under the params tree of the config file. (e.g. /post/some-activity.md

So If .Path replaces .File.BaseFileName, and as long as there's a file under the tree (as outlined by the config file), then the following happens (this is tested with hugo v0.100.1-extended):

WARN  .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 }}

Re-run Hugo with the flag --panicOnWarning to get a better error message.
Total in 6 ms

which introduces a new set of problems obviously, and I clearly have no idea what the the better error message, is all about, since the flag as outlined by hugo makes no difference,

according to hugo documentation https://gohugo.io/variables/files/

.File.BaseFileName the filename without extension (e.g., foo.en)

and

https://gohugo.io/variables/page/

.Type
the [content type](https://gohugo.io/content-management/types/) of the content (e.g., posts).

with that being said, it doesn't matter really what {{ $lengthToCut := mul -1 (add (len .File.BaseFileName) 1) }} specifies. And whether it's a File.BaseFileName in this case. Since it's a path problem, .Foo.Bar will always result in Wrap it in if or with: {{ with .Foo }}{{ .Bar }}{{ end }} warning message from hugo. (e.g., File.Dir or File.Path etc)