Skip to content

Commit

Permalink
Add lazy images
Browse files Browse the repository at this point in the history
  • Loading branch information
AchillesKal committed Apr 7, 2024
1 parent b7607e6 commit 10608d0
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 2 deletions.
6 changes: 6 additions & 0 deletions assets/controllers.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"@symfony/ux-dropzone/dist/style.min.css": true
}
}
},
"@symfony/ux-lazy-image": {
"lazy-image": {
"enabled": true,
"fetch": "eager"
}
}
},
"entrypoints": []
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"symfony/twig-bundle": "7.0.*",
"symfony/ux-autocomplete": "^2.16",
"symfony/ux-dropzone": "^2.16",
"symfony/ux-lazy-image": "^2.16",
"symfony/validator": "7.0.*",
"symfony/yaml": "7.0.*",
"symfonycasts/tailwind-bundle": "^0.5.1",
Expand Down
80 changes: 79 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
Symfony\UX\Autocomplete\AutocompleteBundle::class => ['all' => true],
Exercise\HTMLPurifierBundle\ExerciseHTMLPurifierBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
Symfony\UX\LazyImage\LazyImageBundle::class => ['all' => true],
];
2 changes: 2 additions & 0 deletions config/packages/liip_imagine.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ liip_imagine:
filter_sets:
blog_list:
quality: 75
blog_list_low:
quality: 30
3 changes: 3 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@
"symfony/ux-dropzone": {
"version": "v2.16.0"
},
"symfony/ux-lazy-image": {
"version": "v2.16.0"
},
"symfony/validator": {
"version": "7.0",
"recipe": {
Expand Down
8 changes: 7 additions & 1 deletion templates/blog_post/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@
<figure class="relative">
{# Check if the blog post has a banner image #}
{% if blog_post.banner %}
<img src="{{ asset(uploaded_asset(blog_post.banner)) | imagine_filter('blog_list') }}" alt="{{ blog_post.title }}" class="h-full w-full rounded-3xl object-cover">
<img
src="{{ asset(uploaded_asset(blog_post.banner)) | imagine_filter('blog_list') }}"
alt="{{ blog_post.title }}" class="h-full w-full rounded-3xl object-cover"
{{ stimulus_controller('symfony/ux-lazy-image/lazy-image', {
src: asset(uploaded_asset(blog_post.banner)) | imagine_filter('blog_list_low')
}) }}
>
{% else %}
<div class="min-h-full h-72 flex justify-center items-center bg-gray-200 rounded-3xl fill-gray-500">
<svg xmlns="http://www.w3.org/2000/svg" height="54" viewBox="0 -960 960 960" width="54">
Expand Down

0 comments on commit 10608d0

Please sign in to comment.