Skip to content

Commit

Permalink
fix: hashing images to avoid caching issues (#1012)
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jan 3, 2024
1 parent 2897048 commit f590810
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion layouts/partials/helpers/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@
{{- $static = true -}}
{{- $filename := path.Join "static" $url.Path -}}
{{- if fileExists $filename -}}
{{- $link = .filename | absURL }}
{{- $hash := "" }}
{{- with os.Stat $filename }}
{{- $hash = .ModTime.Format "20060102150405" | md5 }}
{{- end }}
{{- if $hash }}
{{- $link = printf "%s?v=%s" .filename $hash | absURL }}
{{- else }}
{{- $link = .filename | absURL }}
{{- end }}
{{- if not (in $unresizable $ext) -}}
{{- $img = imageConfig $filename -}}
{{- end -}}
Expand Down

0 comments on commit f590810

Please sign in to comment.