Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default image size for lazy loaded images #233

Merged
merged 2 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ target = "assets/js"
source = "assets/scss"
target = "assets/scss"

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

# Shortcuts in the docs section
[[menu.shortcuts]]
name = "<i class='fas fa-level-up-alt'></i>&nbsp;Back to GDQuest.com"
Expand Down Expand Up @@ -102,6 +106,7 @@ privacyEnhanced = true
dir = ":cacheDir/modules"
maxAge = -1


[markup]
defaultMarkdownHandler = "goldmark"

Expand All @@ -110,6 +115,7 @@ defaultMarkdownHandler = "goldmark"
unsafe = true

[module]

[[module.imports]]
path = "github.com/gohugoio/hugo-mod-jslibs/instantpage"

Expand Down
17 changes: 16 additions & 1 deletion layouts/_default/_markup/render-image.html
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
<img loading="lazy" src="{{ .Destination | safeURL }}" alt="{{ .Text }}" {{ with .Title}} title="{{ . }}"{{ end }} />
{{ $path := .Destination | safeURL }}
{{ $alt := .Text }}
{{ $resource := .Page.Resources.GetMatch .Destination }}

{{ with $resource }}
{{ if and (eq .ResourceType "image") (ne .MediaType.SubType "svg") }}
<img src="{{ .Permalink | safeURL }}"
alt="{{ $alt }}"
{{ with .Title}}title="{{ . }}"{{ end }}
{{ with .Width }}width="{{ . }}"{{ end }}
{{ with .Height }}height="{{ . }}"{{ end }}
/>
{{ else }}
<img src="$path" alt="$alt" />
{{ end }}
{{ end }}