Skip to content

Commit

Permalink
Replace image tags with picture tags
Browse files Browse the repository at this point in the history
- Uses Wagtail 5.2 picture tags https://docs.wagtail.org/en/latest/releases/5.2.html#responsive-multi-format-images-with-the-picture-tag
- Each image now has three renditions for avif, webp and jpeg formats
- Some images now have two sizes on top of this (6 renditions in total) for different screen sizes
  • Loading branch information
rachelhsmith authored and lb- committed Jan 31, 2024
1 parent 1df2e8a commit bb23685
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 15 deletions.
2 changes: 2 additions & 0 deletions bakerydemo/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@
("ar", "العربيّة"),
]

WAGTAILIMAGES_AVIF_QUALITY = 60

ADMIN_PASSWORD = os.environ.get("ADMIN_PASSWORD", "changeme")

# Content Security policy settings
Expand Down
4 changes: 2 additions & 2 deletions bakerydemo/templates/base/home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<div class="homepage">

<div class="container-fluid hero">
{% image page.image fill-1920x600 class="hero-image" alt="" %}
{% picture page.image format-{avif,webp,jpeg} fill-{800x650,1920x900} sizes="100vw" class="hero-image" alt="" %}
<div class="hero-gradient-mask"></div>
<div class="container">
<div class="row">
Expand Down Expand Up @@ -55,7 +55,7 @@ <h2>{{ page.promo_title }}</h2>
</div>
{% endif %}
{% if page.promo_image %}
<figure>{% image page.promo_image fill-590x413-c100 %}</figure>
<figure>{% picture page.promo_image format-{avif,webp,jpeg} fill-590x413-c100 %}</figure>
{% endif %}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/base/include/header-blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% if page.image %}
<div class="container-fluid hero hero--blog">
{% image page.image fill-1920x600 class="hero-image" alt="" %}
{% picture page.image format-{avif,webp,jpeg} fill-{800x650,1920x600} sizes="100vw" class="hero-image" alt="" %}
</div>
{% endif %}
<div class="container">
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/base/include/header-hero.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{% if page.image %}
<div class="container-fluid hero">
{% image page.image fill-1920x600 class="hero-image" alt="" %}
{% picture page.image format-{avif,webp,jpeg} fill-{800x650,1920x600} sizes="100vw" class="hero-image" alt="" %}
<div class="hero__container">
<h1 class="hero__title">{{ page.title }}</h1>
</div>
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/base/preview/person.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

{% block content %}
<div>
{% image object.image fill-200x200-c100 class="blog__avatar" %}
{% picture object.image format-{avif,webp,jpeg} fill-200x200-c100 class="blog__avatar" %}
<h2>{{ object.first_name }} {{ object.last_name }}</h2>
<p>{{ object.job_title }}</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/blocks/image_block.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% load wagtailimages_tags %}

<figure>
{% image self.image fill-600x338 loading="lazy" %}
{% picture self.image format-{avif,webp,jpeg} fill-{400x220,600x338} sizes="(max-width: 768px) 200px, 900px" loading="lazy" %}
<figcaption>{{ self.caption }} - {{ self.attribution }}</figcaption>
</figure>
2 changes: 1 addition & 1 deletion bakerydemo/templates/blog/blog_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if page.authors %}
<div class="blog__avatars">
{% for author in page.authors %}
<div class="blog__author">{% image author.image fill-50x50-c100 class="blog__avatar" %}
<div class="blog__author">{% picture author.image format-{avif,webp,jpeg} fill-50x50-c100 class="blog__avatar" %}
{{ author.first_name }} {{ author.last_name }}</div>
{% endfor %}
</div>
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/includes/card/blog-listing-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a class="blog-listing-card__link" href="{% pageurl blog %}">
{% if blog.image %}
<figure class="blog-listing-card__image">
{% image blog.image fill-322x247-c100 loading="lazy" %}
{% picture blog.image format-{avif,webp,jpeg} fill-322x247-c100 loading="lazy" %}
</figure>
{% endif %}
<div class="blog-listing-card__contents">
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/includes/card/listing-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a class="listing-card__link" href="{{ page.url }}">
{% if page.image %}
<figure class="listing-card__image">
{% image page.image fill-180x180-c100 loading="lazy" %}
{% picture page.image format-{avif,webp,jpeg} fill-180x180-c100 loading="lazy" %}
</figure>
{% endif %}
<div class="listing-card__contents">
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/includes/card/location-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="location-card col-sm-4">
<a class="location-card__link" href="{{page.url}}">
<figure class="location-card__image">
{% image page.image fill-430x320-c100 loading="lazy" %}
{% picture page.image format-{avif,webp,jpeg} fill-{300x320-c100,430x320-c100} sizes="(max-width: 768px) 150px, 400px" loading="lazy" %}
</figure>
<div class="location-card__contents">
<h3 class="location-card__title">{{page.title}}</h3>
Expand Down
4 changes: 2 additions & 2 deletions bakerydemo/templates/includes/card/picture-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<a class="picture-card__link" href="{{ page.url }}">
<figure class="picture-card__image">
{% if portrait %}
{% image page.image fill-433x487-c100 loading="lazy" %}
{% picture page.image format-{avif,webp,jpeg} fill-{250x320-c100,433x487-c100} sizes="(max-width: 768px)125px,400px" loading="lazy" %}
{% else %}
{% image page.image fill-645x480-c75 loading="lazy" %}
{% picture page.image format-{avif,webp,jpeg} fill-{300x200-c75,645x480-c75} sizes="(max-width: 768px)150px,30vw" loading="lazy" %}
{% endif %}
<div class="picture-card__contents">
<h3 class="picture-card__title">{{ page.title }}</h3>
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/recipes/recipe_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if page.authors %}
<div class="blog__avatars">
{% for author in page.authors %}
<div class="blog__author">{% image author.image fill-50x50-c100 class="blog__avatar" %}
<div class="blog__author">{% picture author.image format-{avif,webp,jpeg} fill-50x50-c100 class="blog__avatar" %}
{{ author.first_name }} {{ author.last_name }}</div>
{% endfor %}
</div>
Expand Down
3 changes: 2 additions & 1 deletion bakerydemo/templates/search/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ <h1>Search results</h1>
<a class="listing-card__link" href="{% pageurl result.specific %}">
{% if result.specific.image %}
<figure class="listing-card__image">
{% image result.specific.image fill-180x180-c100 loading="lazy" %}
{% picture result.specific.image format-{avif,webp,jpeg} fill-180x180-c100 loading="lazy" %}
</figure>
{% endif %}
<div class="listing-card__contents">
Expand Down Expand Up @@ -75,6 +75,7 @@ <h3 class="listing-card__title">{{ search_promotion.page.specific }}</h3>
{% else %}
<a class="listing-card__link" href="{{ search_promotion.external_link_url }}">
<figure class="listing-card__image">
{% picture search_promotion.page.specific.image format-{avif,webp,jpeg} fill-180x180-c100 loading="lazy" %}
</figure>
<div class="listing-card__contents">
<h3 class="listing-card__title">{{ search_promotion.external_link_text }}</h3>
Expand Down
2 changes: 1 addition & 1 deletion bakerydemo/templates/tags/gallery.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{% for img in images %}
<div class="picture-card">
<figure class="picture-card__image">
{% image img fill-645x480-c100 loading="lazy" %}
{% picture img format-{avif,webp,jpeg} fill-{300x200-c75,645x480-c75} sizes="(max-width: 768px)150px,30vw" loading="lazy" %}
<div class="picture-card__contents">
<p class="picture-card__title">{{ img.title }}</p>
</div>
Expand Down

0 comments on commit bb23685

Please sign in to comment.