gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
76.03k stars 7.54k forks source link

Add .Page.SourceInfo #12998

Open bep opened 3 weeks ago

bep commented 3 weeks ago

In many template error/warning situations (when we don't have any .Pos info), a common need is to have some way of referring to the source, e.g. where to fix the issue, e.g.

{{ warnf "you need to fix the front matter in %s" .Path }}

The problem with the above is that .Path in many cases is not very precise and not something I can just click on and take you to the source.

It would be practical if I would just do:

{{ warnf "you need to fix the front matter in %s" .SourceInfo }}

And the struct printed itself with enough information to take me to the correct content file/adapter.

It's certainly possible to create such reference using ifs and withs, but it's much harder than it should be.

bep commented 2 weeks ago

While the above may be a great idea, I think I'm going to start by making the .Page.String method more useful.