Skip to content

Commit

Permalink
Add default image size for lazy loaded images
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanLovato committed Oct 23, 2020
1 parent da8dd5f commit bcd81e6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ privacyEnhanced = true
dir = ":cacheDir/modules"
maxAge = -1

[module]
[[module.mounts]]
source = "assets/scss"
target = "assets/scss"
[[module.mounts]]
source = "static/img"
target = "assets/img"

[markup]
defaultMarkdownHandler = "goldmark"

Expand Down
16 changes: 15 additions & 1 deletion layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
<img loading="lazy" src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}"{{ end }} />
{{ $image := .Page.Resources.GetMatch .Destination }}
{{ if not $image }}
{{ $image = resources.Get .Destination }}
{{ end }}
{{ with $image }}
{{ warnf "%q" .Permalink }}
<img
src="{{ .Permalink }}"
alt="{{ .Title }}"
loading="lazy"
width="{{ .Width }}"
height="{{ .Height }}"
{{ with .Title}}title="{{ . }}"{{ end }}
/>
{{ end }}

0 comments on commit bcd81e6

Please sign in to comment.