With v0.123 update I’m getting the following error while generating a site:
error calling partial: "…/layouts/partials/figure.html:21:21": execute of template failed: template: partials/figure.html:21:21: executing "partials/figure.html" at <float .>: error calling float: unable to cast big.Rat{a:big.Int{neg:false, abs:big.nat{0x3}}, b:big.Int{neg:false, abs:big.nat{0xa}}} of type big.Rat to float64
What I’m doing is parsing an image EXIF data:
{{ with .file }}
…
{{ with .Exif }}
…
{{ with .Tags.ExposureTime }}
{{ $exposure := 0 }}
{{ if ( hasPrefix . "1/" ) }}
{{ $exposure = ( div 1 ( float ( strings.TrimPrefix "1/" . ) ) ) }}
{{ else }}
{{ $exposure = ( float . ) }}
{{ end }}
…
The error happens on the {{ $exposure = ( float . ) }} line.
I’m not sure why this error happens and why a rational number, 0.3 in this case, cannot be converted into a floating point number. With v0.122 it worked just fine.
The ratio doesn’t begin with 1, the code directly tries to convert 0.3 to float. Why this is not going to work? I don’t understand your answer, sorry. I have these very pictures converted with existing code in v0.122 just fine, the result is visible here: Львів | post-factum's notes
{{ with resources.Get "DSC_0171.JPG" }}
{{ with .Exif }}
{{ with .Tags.ExposureTime }}
{{ $exposure := 0 }}
{{ if ( hasPrefix . "1/" ) }}
{{ $exposure = ( div 1 ( float ( strings.TrimPrefix "1/" . ) ) ) }}
{{ else }}
{{ $exposure = ( float . ) }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
Start building sites …
hugo v0.122.0-b9a03bd59d5f71a529acb3e33f995e0ef332b3aa+extended linux/amd64 BuildDate=2024-01-26T15:54:24Z VendorInfo=gohugoio
Total in 28 ms
Error: error building site: render: failed to render pages: render of "home" failed: "/home/jmooring/code/hugo-testing/layouts/_default/home.html:24:25": execute of template failed: template: _default/home.html:24:25: executing "main" at <float .>: error calling float: unable to cast big.Rat{a:big.Int{neg:false, abs:big.nat{0x3}}, b:big.Int{neg:false, abs:big.nat{0xa}}} of type big.Rat to float64
I’d like to have the exposure converted to float to display it differently later depending on whether it is greater than 1 second or it is less than 1 second.