Skip to content

Commit

Permalink
Update render-image.html to fix dimbox in List View (#636)
Browse files Browse the repository at this point in the history
* Updated the render-image render hook based on the official HUGO embedded render image hook so it works in the List View when noSummary is enabled in the post's front matter.
  • Loading branch information
Sp-cy committed Jun 17, 2024
1 parent bb0b67b commit 9f8e0de
Showing 1 changed file with 34 additions and 4 deletions.
38 changes: 34 additions & 4 deletions v4/layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,42 @@
{{- $u := urls.Parse .Destination -}}
{{- $src := $u.String -}}
{{- if not $u.IsAbs -}}
{{- $path := strings.TrimPrefix "./" $u.Path }}
{{- with or (.PageInner.Resources.Get $path) (resources.Get $path) -}}
{{- $src = .RelPermalink -}}
{{- with $u.RawQuery -}}
{{- $src = printf "%s?%s" $src . -}}
{{- end -}}
{{- with $u.Fragment -}}
{{- $src = printf "%s#%s" $src . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $attributes := merge .Attributes (dict "alt" .Text "src" $src "title" (.Title | transform.HTMLEscape)) -}}

{{- /* Define the href for the anchor tag, it could be same as the image src or another variable */ -}}
{{- $href := $src | default $src -}}

{{ if .Title }}
<figure>
<a href="{{ .Destination | safeURL }}" data-dimbox data-dimbox-caption="{{ .Text }}">
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" />
<a href="{{ $href | safeURL }}" data-dimbox data-dimbox-caption="{{ .Text }}">
<img
{{- range $k, $v := $attributes -}}
{{- if $v -}}
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
{{- end -}}
{{- end -}} />
</a>
<figcaption>{{ .Title }}</figcaption>
</figure>
{{ else }}
<a href="{{ .Destination | safeURL }}" data-dimbox data-dimbox-caption="{{ .Text }}">
<img src="{{ .Destination | safeURL }}" alt="{{ .Text }}" />
<a href="{{ $href | safeURL }}" data-dimbox data-dimbox-caption="{{ .Text }}">
<img
{{- range $k, $v := $attributes -}}
{{- if $v -}}
{{- printf " %s=%q" $k $v | safeHTMLAttr -}}
{{- end -}}
{{- end -}} />
</a>
{{ end }}
{{- /**/ -}}

0 comments on commit 9f8e0de

Please sign in to comment.