Skip to content

fix: handle SVG and non-image resources in image helper and tile template#1276

Open
delize wants to merge 1 commit intoCaiJimmy:masterfrom
delize:fix/svg-and-non-image-resource-handling
Open

fix: handle SVG and non-image resources in image helper and tile template#1276
delize wants to merge 1 commit intoCaiJimmy:masterfrom
delize:fix/svg-and-non-image-resource-handling

Conversation

@delize
Copy link
Contributor

@delize delize commented Feb 21, 2026

Summary

  • helper/image.html: .Resources.Get can return non-image resources (e.g. PDFs, text files in page bundles). Calling .Height/.Width on these causes a build error: this method is only available for image resources. Added an isImage media type check so non-image resources get nil Height/Width, same as SVGs.
  • article-list/tile.html: .Colors is called on any image resource, but it's not available on SVGs, causing: this method is only available for raster images. Added an SVG subtype check before the .Colors call.

How to reproduce

  1. Create a page bundle with a non-image file (e.g. a PDF) that shares a name with the image front matter field, or use an SVG as a featured image
  2. Run hugo build
  3. Build fails with one of the above errors

Test plan

  • Build succeeds with SVG featured images on archive/taxonomy pages (tile layout)
  • Build succeeds with page bundles containing non-image resources
  • Raster images still get correct Width/Height and gradient colors
…late

The `helper/image` partial calls `.Height` and `.Width` on any resource
returned by `.Resources.Get`, but these methods are only available on
raster image resources. Non-image resources (e.g. PDFs in page bundles)
cause a build error: "this method is only available for image resources".

Similarly, `article-list/tile.html` calls `.Colors` on any image
resource, but `.Colors` is not available on SVG resources, causing:
"this method is only available for raster images".

Changes:
- `helper/image.html`: Add `isImage` media type check so non-image
  resources (PDFs, text files, etc.) get nil Height/Width like SVGs
- `article-list/tile.html`: Skip `.Colors` call for SVG resources
@delize
Copy link
Contributor Author

delize commented Feb 21, 2026

Trying to upload the last minor fixes/features I have for things against v4 so I can clean up my own partials layout. Feel free to decline if desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant