好吧,我反悔了… 上一篇刚说完不打算为旧浏览器提供后备图像 ,这就弄上了…

赤果果地水一篇~

{{ $pathArr := split .Destination "." }}
{{ $srcBase := index $pathArr 0 }}

{{ if .Title }}
  <figure>
    {{ if (strings.HasSuffix .Destination ".svg") }}
    <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}">
    {{ else }}
    <picture>
      <source srcset="{{ $srcBase }}.webp" type="image/webp">
      <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}">
    </picture>
    {{ end }}
    <figcaption>{{ .Title }}</figcaption>
  </figure>
{{ else }}
  {{ if (strings.HasSuffix .Destination ".svg") }}
    <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}">
  {{ else }}
    <picture>
      <source srcset="{{ $srcBase }}.webp" type="image/webp">
      <img src="{{ .Destination | safeURL }}" alt="{{ .Text }}">
    </picture>
  {{ end }}
{{ end }}