diff --git a/static/placeholder.svg b/assets/placeholder.svg similarity index 100% rename from static/placeholder.svg rename to assets/placeholder.svg diff --git a/layouts/post/single.html b/layouts/post/single.html index d59445b..4e01443 100644 --- a/layouts/post/single.html +++ b/layouts/post/single.html @@ -47,13 +47,18 @@

{{ .Title }}

{{ if .Site.Params.lazyload }} - {{ $img := findRE "src=\"(.+?png|jpg|jpeg|gif|bmp)\"" .Content }} - {{ if gt (len $img) 1 }} - - {{ (.Content | replaceRE "src=\"(.+?png|jpg|jpeg|gif|bmp)\"" "src=\"/placeholder.svg\" data-src=\"$1\"") | safeHTML }} + + + {{ $regex := "src=\"(.+?)\"" }} + {{ $img := findRE $regex .Content }} + + {{ if gt (len $img) 0 }} + {{ $placeholder := resources.Get "placeholder.svg" }} + {{ $replacement := print "src=\"" $placeholder.RelPermalink "\" data-src=\"$1\"" }} + {{ .Content | replaceRE $regex $replacement | safeHTML }} {{ else }} {{ .Content }} - {{ end }} + {{ end }} {{ else }}