future-wd / hugo-responsive-images

MIT License
57 stars 6 forks source link

Doesn't support latest hugo v0.127.0 #67

Closed garywei944 closed 3 months ago

garywei944 commented 3 months ago

The problem is that .Get and .Param are not officially supported methods for map variables and they are not documented in Hugo (reference). Hugo removed these methods recently, but they are widely used in this plugin, which makes all codes like $ctx.Param "image.type" broken.

Part of the error log

Watching for changes in /home/aris/projects/garywei.dev/{archetypes,assets,content,data,layouts,package.json,static,themes}
Watching for config changes in /home/aris/projects/garywei.dev/config/_default, /home/aris/projects/garywei.dev/config/production, /home/aris/projects/garywei.dev/themes/responsive-images/config/_default, /home/aris/projects/garywei.dev/go.mod
Start building sites … 
hugo v0.127.0+extended linux/amd64 BuildDate=unknown

ERROR Hugo Responsive Images:
Page resource image %!s(<nil>)/images/academic_profile.jpg not found
Built in 34 ms
Error: error building site: render: failed to render pages: render of "home" failed: "/home/aris/projects/garywei.dev/layouts/index.html:5:7": execute of template failed: template: index.html:5:7: executing "main" at <partial (print "body/" . ".html") (merge $params (dict "data" $data))>: error calling partial: execute of template failed: template: partials/body/cover.html:56:13: executing "partials/body/cover.html" at <partial "img" (dict "ctx" . "src" "/images/academic_profile.jpg" "width" 300 "alt" "Test image")>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/img.html:1:3": execute of template failed: template: partials/img.html:1:3: executing "partials/img.html" at <partial "hri/img" .>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/hri/img.html:1:3": execute of template failed: template: partials/hri/img.html:1:3: executing "partials/hri/img.html" at <partial "hri/private/image" (merge . (dict "partial" "img"))>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/hri/private/image.html:31:21": execute of template failed: template: partials/hri/private/image.html:31:21: executing "partials/hri/private/image.html" at <partial "hri/private/params/image.html" $params>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/hri/private/params/image.html:29:14": execute of template failed: template: partials/hri/private/params/image.html:29:14: executing "partials/hri/private/params/image.html" at <partial "hri/private/params/image-general" .>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/hri/private/params/image-general.html:12:118": execute of template failed: template: partials/hri/private/params/image-general.html:12:118: executing "partials/hri/private/params/image-general.html" at <$ctx.Param>: Param is not a method but has arguments
sean-au commented 3 months ago

Thanks Gary I'll get started on it.

On Wed, 26 June 2024, 5:25 am Gary Wei, @.***> wrote:

The problem is that .Get and .Param are not officially supported methods for map variables and they are not documented in Hugo (reference https://github.com/gohugoio/hugo/issues/10862#issuecomment-1614763108). Hugo removed these methods recently, but they are widely used in this plugin, which makes all codes like $ctx.Param "image.type" broken.

Part of the error log

Watching for changes in /home/aris/projects/garywei.dev/{archetypes,assets,content,data,layouts,package.json,static,themes} http://garywei.dev/%7Barchetypes,assets,content,data,layouts,package.json,static,themes%7DWatching for config changes in /home/aris/projects/garywei.dev/config/_default, /home/aris/projects/garywei.dev/config/production, /home/aris/projects/garywei.dev/themes/responsive-images/config/_default, /home/aris/projects/garywei.dev/go.modStart building sites … hugo v0.127.0+extended linux/amd64 BuildDate=unknown ERROR Hugo Responsive Images:Page resource image %!s()/images/academic_profile.jpg not foundBuilt in 34 ms Error: error building site: render: failed to render pages: render of "home" failed: "/home/aris/projects/garywei.dev/layouts/index.html:5:7": execute of template failed: template: index.html:5:7: executing "main" at <partial (print "body/" . ".html") (merge $params (dict "data" $data))>: error calling partial: execute of template failed: template: partials/body/cover.html:56:13: executing "partials/body/cover.html" at <partial "img" (dict "ctx" . "src" "/images/academic_profile.jpg" "width" 300 "alt" "Test image")>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/img.html:1:3": execute of template failed: template: partials/img.html:1:3: executing "partials/img.html" at <partial "hri/img" .>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/hri/img.html:1:3": execute of template failed: template: partials/hri/img.html:1:3: executing "partials/hri/img.html" at <partial "hri/private/image" (merge . (dict "partial" "img"))>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/hri/private/image.html:31:21": execute of template failed: template: partials/hri/private/image.html:31:21: executing "partials/hri/private/image.html" at <partial "hri/private/params/image.html" $params>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/hri/private/params/image.html:29:14": execute of template failed: template: partials/hri/private/params/image.html:29:14: executing "partials/hri/private/params/image.html" at <partial "hri/private/params/image-general" .>: error calling partial: "/home/aris/projects/garywei.dev/themes/responsive-images/layouts/partials/hri/private/params/image-general.html:12:118": execute of template failed: template: partials/hri/private/params/image-general.html:12:118: executing "partials/hri/private/params/image-general.html" at <$ctx.Param>: Param is not a method but has arguments

— Reply to this email directly, view it on GitHub https://github.com/future-wd/hugo-responsive-images/issues/67, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARTWGA6ON5VCY7SIHHO6ARTZJG72FAVCNFSM6AAAAABJ4O4MACVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3TGNBYGU2TAMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

sean-au commented 3 months ago

Hi @garywei944 I just ran the test site (clone the repo and there is a test site folder with a npm script to run a server) with Hugo 1.27.0 and had no error.

I couldn't see any use of .Get for params. I couldn't a reference to .Param being deprecated?

This module could do with some work on how to throw a decent error when I file is missing, or the wrong kind of file is provided.

Do you think that's the issue, or am I off track?

garywei944 commented 3 months ago

Hi Sean, thanks for your quick follow-up. Let me come back to the issue later today.

garywei944 commented 3 months ago

I figured out that the issue is the images path must include assets/ at the beginning for global resourcs. Otherwise the ctx will be set to null at some point and break everything.

Thanks again for the quick response!

However, I encountered a few other bugs that I'm not sure if it's caused by new version of go/hugo.

  1. specify widths in the site-wise params.toml somehow convert list(slice) of int to list of string and throw the following error.

Here is the template I use

{{ partial "figure"  (dict
  "ctx" .
  "src" "assets/images/projects/astronaut/cs590g_p1_start.jpg"
  "attr_link" "http://www.author-page.com"
  "figcaption_title" "Boat x54"
  "caption" "My favourite boat"
  "link" "https://www.google.com"
  "alt" "Academic Profile"
  )
}}

and in params.toml

[image]
widths = [480, 768, 1440]

Here is the error message image

  1. I don't know why but neither the link nor attr_link is rendered? image

FYI, I'm using hugo v0.127.0 with extension and go 1.22.4. Also, I personally found that debugging hugo scripts is painful because I didn't find a way to add breakpoints and debug like using gdb to debug C programs.

sean-au commented 3 months ago

Thanks for the detailed explanation.

I think there has been a similar issue with arrays of ints with Jason files.

If you know what Hugo is doing here let me know.

For debugging purposes I separated this module into simple pages so it's easier to catch the bugs.

Ill let you know how I go.

On Wed, 26 June 2024, 10:41 pm Gary Wei, @.***> wrote:

I figured out that the issue is the images path must include assets/ at the beginning for global resourcs. Otherwise the ctx will be set to null at some point and break everything.

Thanks again for the quick response!

However, I encountered a few other bugs that I'm not sure if it's caused by new version of go/hugo.

  1. specify widths in the site-wise params.toml somehow convert list(slice) of int to list of string and throw the following error.

Here is the template I use

{{ partial "figure" (dict "ctx" . "src" "assets/images/projects/astronaut/cs590g_p1_start.jpg" "attr_link" "http://www.author-page.com" "figcaption_title" "Boat x54" "caption" "My favourite boat" "link" "https://www.google.com" "alt" "Academic Profile" ) }}

and in params.toml

[image]widths = [480, 768, 1440]

Here is the error message image.png (view on web) https://github.com/future-wd/hugo-responsive-images/assets/33930674/f0a432d5-4a3d-445e-9e4c-a5ad18e41eea

  1. I don't know why but neither the link nor attr_link is rendered? image.png (view on web) https://github.com/future-wd/hugo-responsive-images/assets/33930674/49211202-f339-462d-8539-fc7ba27a5c53

FYI, I'm using hugo v0.127.0 with extension and go 1.22.4. Also, I personally found that debugging hugo scripts is painful because I didn't find a way to add breakpoints and debug like using gdb to debug C programs.

— Reply to this email directly, view it on GitHub https://github.com/future-wd/hugo-responsive-images/issues/67#issuecomment-2191593986, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARTWGA6XHBGDAPCCXVCJLHLZJKZF7AVCNFSM6AAAAABJ4O4MACVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOJRGU4TGOJYGY . You are receiving this because you commented.Message ID: @.***>

sean-au commented 3 months ago

Thanks for your help!

On Thu, 27 June 2024, 10:57 am Gary Wei, @.***> wrote:

Closed #67 https://github.com/future-wd/hugo-responsive-images/issues/67 as completed.

— Reply to this email directly, view it on GitHub https://github.com/future-wd/hugo-responsive-images/issues/67#event-13305762370, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARTWGA4NDR7QVYIC4BV3HPLZJNPQ5AVCNFSM6AAAAABJ4O4MACVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJTGMYDKNZWGIZTOMA . You are receiving this because you commented.Message ID: @.*** com>

sean-au commented 3 months ago

@garywei944 if you have any breaking changes for a v2 wish list please let me know