Skip to content

Commit

Permalink
fix: do not optimise inline base64 images (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
HEIGE-PCloud authored Sep 15, 2024
1 parent 3ff3bdb commit c788650
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions layouts/partials/plugin/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
- CacheRemote: Override the site parameter to cache remote images.
*/}}

{{- $isInlineImage := strings.HasPrefix .Src "data:image" -}}

{{- $resource := dict -}}
{{/* Do not call resources.Get on remote resources. https://github.com/HEIGE-PCloud/DoIt/issues/1300 */}}
{{/* Do not call resources.Get on remote resources. https://github.com/HEIGE-PCloud/DoIt/issues/1300
Do not call try to get a resource if the image is inline. https://github.com/HEIGE-PCloud/DoIt/issues/1345
*/}}
{{- $isUrlRemote := urls.Parse .Src | partial "function/isUrlRemote.html" -}}
{{- if not $isUrlRemote -}}
{{- if not $isUrlRemote | and (not $isInlineImage) -}}
{{- $resource = (.Resources.Get .Src) | default (resources.Get .Src) -}}
{{- end -}}

Expand Down Expand Up @@ -67,7 +71,7 @@
{{- if .Linked -}}
<a class="lightgallery" href="{{ $src }}" title="{{ .Title | default .Alt }}" data-thumbnail="{{ $src }}"{{ with .Caption }} data-sub-html="<h2>{{ . }}</h2>{{ with $.Title }}<p>{{ . }}</p>{{ end }}"{{ end }}{{ with .Rel }} rel="{{ . }}"{{ end }}>
{{- end -}}
<img {{ with .Class }}class="{{ . }}"{{ end }} {{ with .Loading }}loading="{{ . }}"{{ end }} src="{{ $src }}" {{ with $srcset }}srcset="{{ . }}"{{ end }} {{ with .Sizes }}sizes="{{ . }}"{{ end }} {{ with $alt }}alt="{{ . }}"{{ end }} {{ with $height }}height="{{ . }}"{{ end }} {{ with $width }}width="{{ . }}"{{ end }}>
<img {{ with .Class }}class="{{ . }}"{{ end }} {{ with .Loading }}loading="{{ . }}"{{ end }} {{ print "src=" $src | safeHTMLAttr }} {{ with $srcset }}srcset="{{ . }}"{{ end }} {{ with .Sizes }}sizes="{{ . }}"{{ end }} {{ with $alt }}alt="{{ . }}"{{ end }} {{ with $height }}height="{{ . }}"{{ end }} {{ with $width }}width="{{ . }}"{{ end }}>
{{- if .Linked -}}
</a>
{{- end -}}

0 comments on commit c788650

Please sign in to comment.