Skip to content

Commit

Permalink
fix(post): external images build fails on Windows
Browse files Browse the repository at this point in the history
Fixed #537
  • Loading branch information
razonyang committed May 24, 2022
1 parent 86db6b7 commit af920d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
13 changes: 8 additions & 5 deletions layouts/partials/post/featured-image.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
{{- $formats := slice "avif" "webp" "jxl" -}}
<picture>
{{- $img := index .Params.images 0 -}}
{{- $ext := $img | path.Ext }}
{{- range $formats -}}
{{- $filename := replace $img $ext (printf ".%s" .) -}}
{{- if and (not (strings.HasSuffix $ext .)) (fileExists (path.Join "static" $filename)) -}}
<source srcset="{{ $filename | absURL }}" type="image/{{ . }}" />
{{- $url := urls.Parse $img -}}
{{- if not $url.Scheme -}}
{{- $ext := $img | path.Ext }}
{{- range $formats -}}
{{- $filename := replace $img $ext (printf ".%s" .) -}}
{{- if and (not (strings.HasSuffix $ext .)) (fileExists (path.Join "static" $filename)) -}}
<source srcset="{{ $filename | absURL }}" type="image/{{ . }}" />
{{- end -}}
{{- end -}}
{{- end -}}
<img class="post-featured-img w-100 mb-3" alt="{{ .Title }}" src="{{ $img | absURL }}" loading="lazy"/>
Expand Down
13 changes: 8 additions & 5 deletions layouts/partials/post/thumbnail.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
<picture>
{{- $img := index .Params.images 0 -}}
{{- $ext := $img | path.Ext }}
{{- range $formats -}}
{{- $filename := replace $img $ext (printf ".%s" .) -}}
{{- if and (not (strings.HasSuffix $ext .)) (fileExists (path.Join "static" $filename)) -}}
<source srcset="{{ $filename | absURL }}" type="image/{{ . }}" />
{{- end -}}
{{- $url := urls.Parse $img -}}
{{- if not $url.Scheme -}}
{{- range $formats -}}
{{- $filename := replace $img $ext (printf ".%s" .) -}}
{{- if and (not (strings.HasSuffix $ext .)) (fileExists (path.Join "static" $filename)) -}}
<source srcset="{{ $filename | absURL }}" type="image/{{ . }}" />
{{- end -}}
{{- end -}}
{{- end -}}
<img class="img-fluid" alt="{{ .Title }}" src="{{ $img | absURL }}" loading="lazy"/>
</picture>
Expand Down

0 comments on commit af920d9

Please sign in to comment.