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

Switches to lazyimg base #5

Merged
merged 2 commits into from Sep 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.