Skip to content

Commit

Permalink
lazy load
Browse files Browse the repository at this point in the history
  • Loading branch information
jesselau76 committed Nov 27, 2018
1 parent 57f5b3c commit afb6fb6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
File renamed without changes
15 changes: 10 additions & 5 deletions layouts/post/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ <h1>{{ .Title }}</h1>
<!-- Content -->
<div class="w3-container">
{{ 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 }}
Expand Down

0 comments on commit afb6fb6

Please sign in to comment.