Skip to content

Commit

Permalink
feat: support animated featured images (GIFs)
Browse files Browse the repository at this point in the history
Add support for animated GIFs (e.g. featured.gif) in instances of the featured image in page header and all views
  • Loading branch information
gcushen committed Oct 19, 2023
1 parent 2fc3e6a commit b70eaa9
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
7 changes: 4 additions & 3 deletions modules/wowchemy/layouts/partials/page_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,15 @@
{{ $image_container := "" }}
{{ if eq $placement 2}}
{{ $image_container = "container" }}
{{ $image = $featured.Fit "1200x2500 webp" }}
{{ $image = $featured.Fit "1200x2500" }}
{{else if eq $placement 3}}
{{ $image_container = "container-fluid" }}
{{ $image := $featured.Fit "2560x2560 webp" }}
{{ $image := $featured.Fit "2560x2560" }}
{{else}}
{{ $image_container = "article-container" }}
{{ $image = $featured.Fit "720x2500 webp" }}
{{ $image = $featured.Fit "720x2500" }}
{{end}}
{{ if ne $image.MediaType.SubType "gif" }}{{ $image = $image.Process "webp" }}{{ end }}

<div class="article-container pt-3">
<h1>{{ $title }}</h1>
Expand Down
3 changes: 2 additions & 1 deletion modules/wowchemy/layouts/partials/views/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
{{ $resource := partial "functions/get_featured_image.html" $item }}
{{ $anchor := $item.Params.image.focal_point | default "Smart" }}
{{ with $resource }}
{{ $image := .Fill (printf "808x455 webp %s" $anchor) }}
{{ $image := .Fill (printf "808x455 %s" $anchor) }}
{{ if ne $image.MediaType.SubType "gif" }}{{ $image = $image.Process "webp" }}{{ end }}
<a href="{{ $link }}" {{ $target | safeHTMLAttr }}>
<div class="img-hover-zoom">
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
Expand Down
3 changes: 2 additions & 1 deletion modules/wowchemy/layouts/partials/views/compact.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
<div class="ml-3">
{{ $resource := partial "functions/get_featured_image.html" $item }}
{{ with $resource }}
{{ $image := .Resize "150x webp" }}
{{ $image := .Resize "150x" }}
{{ if ne $image.MediaType.SubType "gif" }}{{ $image = $image.Process "webp" }}{{ end }}
<a href="{{$link}}" {{ $target | safeHTMLAttr }}>
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
alt="{{ $item.Title }}" loading="lazy">
Expand Down
3 changes: 2 additions & 1 deletion modules/wowchemy/layouts/partials/views/masonry.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

<div class="card">
{{ with $resource }}
{{ $image := .Resize "550x webp" }}
{{ $image := .Resize "550x" }}
{{ if ne $image.MediaType.SubType "gif" }}{{ $image = $image.Process "webp" }}{{ end }}
<a href="{{ $link }}" {{ $target | safeHTMLAttr }} class="card-image hover-overlay">
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
alt="{{ $item.Title }}" class="img-responsive" loading="lazy">
Expand Down
7 changes: 5 additions & 2 deletions modules/wowchemy/layouts/partials/views/showcase.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@
{{ $resource := partial "functions/get_featured_image.html" $item }}

{{ with $resource }}
{{ $image := .Resize "540x webp" }}
{{/* Use CSS to expand images to consistent widths rather than just Hugo as Hugo can significantly increase the
filesize of GIFs when processing them, e.g. 400kB --> 1.5MB */}}
{{ $image := . }}
{{ if ne $image.MediaType.SubType "gif" }}{{ $image = $image.Process "resize 540x webp" }}{{ end }}
{{if $do_link}}<a href="{{ $link }}" {{ $target | safeHTMLAttr }}>{{end}}
<img src="{{ $image.RelPermalink }}" height="{{ $image.Height }}" width="{{ $image.Width }}"
alt="{{ $item.Title }}" loading="lazy">
alt="{{ $item.Title }}" loading="lazy" style="width: 540px; height: auto; object-fit: cover;">
{{if $do_link}}</a>{{end}}
{{end}}
</div>
Expand Down

0 comments on commit b70eaa9

Please sign in to comment.