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

Conversation

NathanLovato
Copy link
Collaborator

Uses hugo's resources to set the width and height attribute of lazy-loaded images so they don't pop on the screen, pushing the content down.

Part of #228

@NathanLovato NathanLovato marked this pull request as draft October 23, 2020 04:31
@NathanLovato
Copy link
Collaborator Author

There's an issue left, some pictures trigger an error; hugo doesn't recognize them as resources and I can't figure out why. I asked for help on the hugo forum: https://discourse.gohugo.io/t/error-with-imageconfig-image-unknown-format/28985/7

@NathanLovato NathanLovato force-pushed the feature/lazy-image-size branch from 720eb70 to 20ccb2e Compare March 28, 2021 21:42
Here were the problems, and here’s the solution:

1. I had to mount the static folder to assets/ as suggested by @bep to
be able to get all images as resources
2. You have to be careful about some types, like for example if you call
safeURL on a path the returned object isn’t a string, so you can’t pass
it to .Page.Resources.GetMatch
3. I had to use the .Page object to get resources.
4. Trying to evaluate width and height on an SVG resource fails. We use
some SVGs in Markdown, as we sometimes use the format for lightweight
game sprites and other graphic design.
@NathanLovato NathanLovato marked this pull request as ready for review March 29, 2021 15:10
@NathanLovato NathanLovato merged commit db870f0 into master Mar 29, 2021
@NathanLovato NathanLovato deleted the feature/lazy-image-size branch March 29, 2021 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant