Skip to content

Commit

Permalink
Merge pull request #5 from h-enk/lazyimg
Browse files Browse the repository at this point in the history
Switches to lazyimg base
  • Loading branch information
h-enk committed Sep 27, 2022
2 parents 3aa2a45 + b0d9531 commit 67f05be
Show file tree
Hide file tree
Showing 45 changed files with 344 additions and 824 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021-2022 Daniel F. Dickinson, Henk Verlinde
Copyright (c) 2021-2022 Henk Verlinde

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
27 changes: 19 additions & 8 deletions README.md
@@ -1,6 +1,6 @@
# Hyas images

Image render hook + shortcode for Hyas sites.
Image render hook, shortcode + partial for Hyas sites.

## Status

Expand Down Expand Up @@ -29,12 +29,23 @@ Add to `./config/_default/module.toml`:
Add to `./config/_default/params.toml`:

```bash
# Images
imageResponsive = true
imageConvertTo = "webp"
imageImageSizes = ["480","720","1080","1280","1600","2048"]
singleSize = false
imageAddClass = "img-fluid lazyload blur-up"
# lazyimg
[lazyimg]
resizer = "auto"
renderer = "lqip-webp"

# Resizer options:
lqipSize = "120x Gaussian"
maxSize = "1920x"
responsiveSizes = [ "320x", "640x", "768x", "1024x", "1366x", "1600x", "1920x" ]
resizeOptions = "Lanczos q95"

# Renderer options:
class = "img-fluid"
# alt = ""
noscript = true

errorHandler = "warning"
```

## Usage
Expand All @@ -44,4 +55,4 @@ See the Hyas docs: [Images](https://gethyas.com/docs/recipes/images/)

## Credits

Based on [DFD Hugo image handling module](https://github.com/danielfdickinson/image-handling-mod-hugo-dfd)
Based on [hugo-mods/lazyimg](https://github.com/hugo-mods/lazyimg)
23 changes: 17 additions & 6 deletions config/_default/params.toml
@@ -1,6 +1,17 @@
# Images
imageResponsive = true
imageConvertTo = "webp"
imageImageSizes = ["480","720","1080","1280","1600","2048"]
singleSize = false
imageAddClass = " img-fluid lazyload blur-up"
# lazyimg
[lazyimg]
resizer = "auto"
renderer = "lqip-webp"

# Resizer options:
lqipSize = "120x Gaussian"
maxSize = "1920x"
responsiveSizes = [ "320x", "640x", "768x", "1024x", "1366x", "1600x", "1920x" ]
resizeOptions = "Lanczos q95"

# Renderer options:
class = "img-fluid"
# alt = ""
noscript = true

errorHandler = "warning"
14 changes: 8 additions & 6 deletions layouts/_default/_markup/render-image.html
@@ -1,6 +1,8 @@
{{- $markdownImageLinkClass := .Page.Params.imageMarkdownLinkClass | default .Page.Site.Params.imageMarkdownLinkClass -}}
{{- $markdownImageClass := .Page.Params.imageMarkdownClass | default .Page.Site.Params.imageMarkdownClass -}}
{{- $markdownImageWrapper := .Page.Params.imageMarkdownAddWrapper | default .Page.Site.Params.imageMarkdownAddWrapper -}}
{{- $image := partial "helpers/lib/image-handling/find-image-src" (dict "src" .Destination "page" .Page "getRelative" true "ignoreBundleAssets" false) -}}
{{- partial "helpers/wrapped-image" (dict "alt" .Text "altRendered" true "title" .Title "image" $image "page" .Page "noImageWrapper" (not $markdownImageWrapper) "linkClass" $markdownImageLinkClass "class" $markdownImageClass) -}}
{{- /* Remove trailing newlines */ -}}
{{ $img := .Destination }}
{{ $alt := .Text -}}
{{ $params := (dict "img" $img "alt" $alt) -}}
{{ if not (resources.Get $params.img) -}}
{{ $params = merge $params (dict "img" (.Page.Resources.GetMatch $params.img)) -}}
{{ end -}}

{{ partial "lazyimg" $params }}
1 change: 1 addition & 0 deletions layouts/partials/error-handler/error.html
@@ -0,0 +1 @@
{{ errorf "image path './assets/%s' does not exist. please check the 'assets' directory." .img }}
12 changes: 12 additions & 0 deletions layouts/partials/error-handler/warning-remote.html
@@ -0,0 +1,12 @@
{{ $params := . }}
{{ $url := .img | absURL }}
{{ warnf "image path './assets/%s' does not exist. trying remote get via %s" .img $url }}
{{ $res := false }}
{{ with $resource := resources.GetRemote $url }}
{{ with .Err }}
{{ warnf "could not get remotely: %s: %#v" .Error .Data }}
{{ else }}
{{ $res = merge $params (dict "img" $resource) }}
{{ end }}
{{ end }}
{{ return $res }}
1 change: 1 addition & 0 deletions layouts/partials/error-handler/warning.html
@@ -0,0 +1 @@
{{ warnf "image path './assets/%s' does not exist. please check the 'assets' directory." .img }}
13 changes: 0 additions & 13 deletions layouts/partials/helpers/featured-image-link.html

This file was deleted.

11 changes: 0 additions & 11 deletions layouts/partials/helpers/featured-image.html

This file was deleted.

5 changes: 0 additions & 5 deletions layouts/partials/helpers/featured-images.html

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

39 changes: 0 additions & 39 deletions layouts/partials/helpers/lib/image-handling/find-image-maps.html

This file was deleted.

0 comments on commit 67f05be

Please sign in to comment.