-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update render-image.html to fix dimbox in List View (#636)
* 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
Showing
1 changed file
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
{{- /**/ -}} |