Skip to content

Conversation

gijoe88
Copy link

@gijoe88 gijoe88 commented Aug 13, 2025

What does this PR change? What problem does it solve?

Double negation in the index-profile partial was resulting in "if at least one of .imageHeight or .imageWidth is provided, then ...". Now it's "if both .imageWidth and .imageHeight are provided, then ...".

Was the change discussed in an issue or in the Discussions before?

Closes #1780

PR Checklist

  • This change adds/updates translations and I have used the template present here.
  • I have enabled maintainer edits for this PR.
  • I have verified that the code works as described/as intended.
  • This change adds a Social Icon which has a permissive license to use it.
  • This change does not include any CDN resources/links.
  • This change does not include any unrelated scripts such as bash and python scripts.
  • This change updates the overridden internal templates from HUGO's repository.

Double negation was resulting in "if at least one of .imageHeight or .imageWidth is provided, then ...". Now it's "if both .imageWidth and .imageHeight are provided, then ..."
Copy link

@adityatelange
Copy link
Owner

Double negation in the index-profile partial was resulting in "if at least one of .imageHeight or .imageWidth is provided, then ...". Now it's "if both .imageWidth and .imageHeight are provided, then ...".

what?

@gijoe88
Copy link
Author

gijoe88 commented Aug 13, 2025

I do not think that the piece of code if (not (and (not .imageHeight) (not .imageWidth))) }} was evaluating the intended condition.

If I include the following conditions, it was resulting in

if .imageHeight is not nil OR .imageWidth is not nil, then
    do resize on both dimension
else if  .imageHieght is not nil then        <= would never evaluate to true, because it is included in the first condition
    do resize on imageHeight
else if .imageWidth is not nil then          <= would never evaluate to true, because it is included in first condition
    do resize on imageWidth 
else
do resize to 150x150px
end

At least it is what I'm understanding, I'm new at this Hugo templating...

If I'm right, I'm proposing to simplify the first condition, into

if both imageHeight and imageWidth are provided, then

@adityatelange
Copy link
Owner

Give it a try, set height and see the results and set width and see the results. We are letting user set one of them and not necessarily both should be set.

@gijoe88
Copy link
Author

gijoe88 commented Aug 13, 2025

I understand that. But the usage of if not ( and ( not X ) ( not Y ) ) does not seem quite right to me.
To simplify, NOT ( V AND W ) is equal to ( NOT V ) OR ( NOT W).
Which means in this case if or ( not ( not X) ) ( not ( not Y ) ). And that results in if or X Y
Replacing the examples X and Y, if ( or .imageHeight .imageWidth ), which did not seem to be the intent.

I'll try changing only one, I did not need it in my site. Maybe this ticket is a non-issue, because of the formatting after that
{{- $img = $img.Resize (printf "%dx%d" .imageWidth .imageHeight) }} which may give the desired effect by replacing nil values by an empty string. If that's the case, the two tests below that might be useless.

@gijoe88
Copy link
Author

gijoe88 commented Aug 14, 2025

Give it a try, set height and see the results and set width and see the results. We are letting user set one of them and not necessarily both should be set.

I tested on my site without the modification. Hugo throws an error when

  • only one dimension is given
  • AND the image is in the assets folder
  • AND the environment is "production"

No issue with my change.

I created the issue #1780

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: In the config, in imageProfileMode, error when setting only one dimension
2 participants