Skip to content

Commit

Permalink
🐛 Fix: image rendering not support base64 syntax (#540)
Browse files Browse the repository at this point in the history
Close #540
  • Loading branch information
Lruihao committed Nov 7, 2024
1 parent 2a0821f commit 5518053
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- /* TODO refactor */ -}}
{{- $params := .Page.Params | merge site.Params.page -}}
{{- if .Title | and .Text -}}
{{- $linked := ne $params.lightgallery false -}}
Expand Down
2 changes: 1 addition & 1 deletion layouts/partials/init/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- .Scratch.Set "version" "v0.3.15-3ead0107" -}}
{{- .Scratch.Set "version" "v0.3.15-2a0821f5" -}}
{{- .Scratch.Set "this" dict -}}

{{- partial "init/detection-env.html" . -}}
Expand Down
11 changes: 8 additions & 3 deletions layouts/partials/plugin/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
{{- $onerror := "" -}}
{{- $cacheRemoteImages := $params.cacheRemoteImages -}}
{{- $suffixList := slice ".jpeg" ".jpg" ".png" ".gif" ".bmp" ".tif" ".tiff" ".webp" -}}
{{- $responsive := .Responsive -}}

{{- if hasPrefix .Src "data:image" -}}
{{- $responsive = false -}}
{{- end -}}

{{- /* handle for default size image */ -}}
{{- $src := .Src -}}
Expand All @@ -17,7 +22,7 @@
{{- $src = .RelPermalink -}}
{{- end -}}
{{- /* only available for image resources that are raster images */ -}}
{{- if (eq .ResourceType "image") | and $suffixValid | and $.Responsive -}}
{{- if (eq .ResourceType "image") | and $suffixValid | and $responsive -}}
{{- $style = printf "--width: %vpx;--aspect-ratio: %v / %v;" .Width .Width .Height | safeHTMLAttr -}}
{{- end -}}
{{- end -}}
Expand All @@ -26,7 +31,7 @@
{{- $srcMedium := $src -}}
{{- $srcLarge := .SrcLarge | default $src -}}

{{- if .Responsive }}
{{- if $responsive }}
{{- /* handle for small size image */ -}}
{{- $suffixValidSmall := dict "Path" $srcSmall "Suffixes" $suffixList | partial "function/suffix-validation.html" -}}
{{- with dict "Path" .SrcSmall "Resources" .Resources "CacheRemoteImages" $cacheRemoteImages.enable | partial "function/resource.html" -}}
Expand Down Expand Up @@ -89,7 +94,7 @@
<a class="lightgallery" href="{{ $srcLarge | safeURL }}" data-thumbnail="{{ $srcSmall | safeURL }}"{{ with $caption }} data-sub-html="<h2>{{ . }}</h2>{{ with $.Title }}<p>{{ . }}</p>{{ end }}"{{ end }}{{ with .Rel }} rel="{{ . }}"{{ end }}>
{{- end -}}
<img loading="{{ $loading }}" src="{{ $src | safeURL }}" alt="{{ $alt }}"
{{- if .Responsive }} srcset="{{ $srcSmall | safeURL }}, {{ $srcMedium | safeURL }} 1.5x, {{ $srcLarge | safeURL }} 2x"{{- end -}}
{{- if $responsive }} srcset="{{ $srcSmall | safeURL }}, {{ $srcMedium | safeURL }} 1.5x, {{ $srcLarge | safeURL }} 2x"{{- end -}}
{{- if eq $loading "lazy" }} data-title="{{ .Title | default $alt }}"
{{- else }} title="{{ .Title | default $alt }}"{{- end -}}
{{- with .Width }} width="{{ . }}"{{- end -}}
Expand Down

0 comments on commit 5518053

Please sign in to comment.