-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix section index partial NPE #1890
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just ran into the same issue, and the fix proposed with this PR solved my problem.
I realized that this contribution proposes a slight more elegant solution to the problem .
@tobiaskohlbau: can you have a look, please? Can we take over this solution here?
AFAIK the proposed solution would not work. As the and within the if only checks for the currently scoped Parent but not for every pages |
Hello, I confirm what @tobiaskohlbau said. Using Hugo 0.124.1, which contains the fix referred to above, on a docs only site, that is with the following front matter in
I still get a warning:
But the warning is solved when adding the modified partial from this PR. |
I re-tested today and, in fact, this is not a warning, but an error:
I still confirm this PR fixes the issue. |
You are right. Your solution is more general and should be merged unchanged. |
@@ -4,7 +4,8 @@ | |||
{{ $pages = (where $pages "Type" "!=" "search") }} | |||
{{ $pages = (where $pages ".Params.hide_summary" "!=" true) -}} | |||
{{ $pages = (where $pages ".Parent" "!=" nil) -}} | |||
{{ if and .Parent .Parent.File -}} | |||
{{ $pages = (where $pages ".Parent.File" "!=" nil) -}} | |||
{{ if and $parent $parent.File -}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at this more closely, it seems to make sense indeed.
Btw, the $parent
variable is misnamed, because$parent
is set to .Page
.
Can we inline the variable instead?
Btw, IMHO .Page
cannot be falsy, but .Page.File
could be falsy. So the if condition can be simplified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will track separately:
During rendering the section index of a docs list it could happen that a file has no parent for e.g. the homepage. If such scenario is existing the .Parent.File of a file is nil. Therefore this case should be handled within the rendering itself. Fixes google#1874 Signed-off-by: Tobias Kohlbau <tobias@kohlbau.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to give this a try.
RSLGTM based on appraisals by @deining and @yann-soubeyrand.
Thanks all! ✨
During rendering the section index of a docs list it could happen that a file has no parent for e.g. the homepage. If such scenario is existing the .Parent.File of a file is nil. Therefore this case should be handled within the rendering itself.
Fixes #1874