Skip to content

[BUG] img partial fails with SVG resources due to .Width/.Height usage #989

@m-hidehiro

Description

@m-hidehiro

Describe the bug 描述你遇到的错误

build error
img partial fails with SVG resources due to .Width/.Height usage

Expected behavior 期待的行为

Successful site build.

Screenshots 屏幕截图

Call svg as an image in a content markdown file.
![Hugo logo](hugo-logo-wide.svg)

When building, the following error message appears and the build fails

... plugin/img.html:7:34: executing "_partials/plugin/img.html" at <.Width>:
error calling Width: this method is only available for raster images.

Build Environment 构建环境

  • OS: windows 11
  • Theme version/commit v0.3.0
  • Hugo version hugo v0.148.2-40c3d8233d4b123eff74725e5766fc6272f0a84d+extended windows/amd64

Additional Information 补充信息

SVG Can it be avoided by judging?
You can build it anyway by rewriting the following code, but I am sure there is a smarter way to do it

{{- /* Pre-extension determination (LOWER with uppercase extension measures) */ -}}
{{- $srcLower := lower $src -}}
{{- $isSVGMain := strings.HasSuffix $srcLower ".svg" -}}

{{- /* Resource resolution of the main image (if SVG, width/height is not complementary). */ -}}
{{- with dict "Path" $src "Resources" .Resources | partial "function/resource.html" -}}
{{- $src = .RelPermalink -}}
{{- if not $isSVGMain -}}
{{- $width = $width | default .Width -}}
{{- $height = $height | default .Height -}}
{{- end -}}
{{- end -}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions