Skip to content

Commit 9fb4d81

Browse files
committed
To Webp
1 parent 95336f6 commit 9fb4d81

4 files changed

Lines changed: 32 additions & 57 deletions

File tree

assets/css/tailwind-input.css

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,6 @@
8282
@apply absolute inset-0 overflow-hidden transition-opacity duration-1000 ease-in-out;
8383
}
8484

85-
.home-hero__bg-layer picture {
86-
@apply block h-full w-full;
87-
}
88-
8985
.home-hero__bg-img {
9086
@apply h-full w-full object-cover object-center;
9187
}

data/homepage.yaml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,15 @@ hero:
8989
searchPlaceholder: "Search tools, games, AI apps..."
9090
autoplayMs: 6000
9191
slides:
92-
- image: "/images/hero/slide-1.jpg"
93-
imageWebp: "/images/hero/slide-1.webp"
92+
- image: "/images/hero/slide-1.webp"
9493
imageAlt: "Team collaborating on laptops"
9594
title: "Tools, games & AI in your browser"
9695
description: "This is a platform where we learn, work on experimental projects, play games, come up with innovative ideas, and build many more..."
97-
- image: "/images/hero/slide-2.jpg"
98-
imageWebp: "/images/hero/slide-2.webp"
96+
- image: "/images/hero/slide-2.webp"
9997
imageAlt: "Developers working together at a desk"
10098
title: "Build faster with CodeFryDev"
10199
description: "From JSON playgrounds to design lab resources—everything runs in your browser."
102-
- image: "/images/hero/slide-3.jpg"
103-
imageWebp: "/images/hero/slide-3.webp"
100+
- image: "/images/hero/slide-3.webp"
104101
imageAlt: "Laptop showing code on a desk"
105102
title: "No install. Just open and use."
106103
description: "Explore creative assets, productivity tools, games, and AI helpers in one place."

layouts/partials/home/hero.html

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,27 @@
99
<section id="hero" data-section-label="Home" class="home-hero relative text-center flex flex-col items-center justify-center px-4 py-8 overflow-hidden bg-[#edf2f8]" aria-roledescription="carousel" aria-label="Featured highlights">
1010
<div class="home-hero__bg" aria-hidden="true">
1111
<div id="bg-layer-1" class="home-hero__bg-layer opacity-100">
12-
<picture>
13-
<source type="image/webp" srcset="{{ $firstSlide.imageWebp }}">
14-
<img
15-
id="hero-bg-img-1"
16-
src="{{ $firstSlide.image }}"
17-
alt=""
18-
width="1600"
19-
height="840"
20-
class="home-hero__bg-img"
21-
fetchpriority="high"
22-
decoding="async"
23-
>
24-
</picture>
12+
<img
13+
id="hero-bg-img-1"
14+
src="{{ $firstSlide.image }}"
15+
alt=""
16+
width="1600"
17+
height="840"
18+
class="home-hero__bg-img"
19+
fetchpriority="high"
20+
decoding="async"
21+
>
2522
</div>
2623
<div id="bg-layer-2" class="home-hero__bg-layer opacity-0">
27-
<picture>
28-
<source type="image/webp">
29-
<img
30-
id="hero-bg-img-2"
31-
alt=""
32-
width="1600"
33-
height="840"
34-
class="home-hero__bg-img"
35-
loading="lazy"
36-
decoding="async"
37-
>
38-
</picture>
24+
<img
25+
id="hero-bg-img-2"
26+
alt=""
27+
width="1600"
28+
height="840"
29+
class="home-hero__bg-img"
30+
loading="lazy"
31+
decoding="async"
32+
>
3933
</div>
4034
</div>
4135
<div class="home-hero__overlay" aria-hidden="true"></div>

static/js/home-hero.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,14 @@
2727
const autoplayMs = prefersReducedMotion ? 0 : Number(window.heroAutoplayMs) || 6000;
2828
const fadeMs = prefersReducedMotion ? 0 : 500;
2929

30-
function setLayerImage(layerEl, slide) {
31-
if (!layerEl || !slide) return;
32-
var picture = layerEl.querySelector('picture');
33-
if (picture) {
34-
var webp = picture.querySelector('source[type="image/webp"]');
35-
var img = picture.querySelector('img');
36-
if (webp && slide.imageWebp) webp.srcset = slide.imageWebp;
37-
if (img && slide.image) img.src = slide.image;
38-
return;
39-
}
40-
var imgOnly = layerEl.querySelector('img');
41-
if (imgOnly && slide.image) {
42-
imgOnly.src = slide.image;
30+
function setLayerImage(layerEl, url) {
31+
if (!layerEl || !url) return;
32+
var img = layerEl.querySelector('img');
33+
if (img) {
34+
img.src = url;
4335
return;
4436
}
45-
if (slide.image) {
46-
layerEl.style.backgroundImage = "url('" + String(slide.image).replace(/'/g, "\\'") + "')";
47-
}
37+
layerEl.style.backgroundImage = "url('" + String(url).replace(/'/g, "\\'") + "')";
4838
}
4939

5040
function syncLadybugBackup() {
@@ -55,11 +45,9 @@
5545
}
5646

5747
heroSlides.forEach(function (slide) {
58-
[slide.imageWebp, slide.image].forEach(function (url) {
59-
if (!url) return;
60-
var img = new Image();
61-
img.src = url;
62-
});
48+
if (!slide.image) return;
49+
var img = new Image();
50+
img.src = slide.image;
6351
});
6452

6553
heroSlides.forEach(function (slide, index) {
@@ -125,7 +113,7 @@
125113
const nextLayer = activeLayer === 1 ? bgLayer2 : bgLayer1;
126114
const currentLayerEl = activeLayer === 1 ? bgLayer1 : bgLayer2;
127115

128-
setLayerImage(nextLayer, slide);
116+
setLayerImage(nextLayer, slide.image);
129117

130118
if (fadeMs === 0) {
131119
applySlideContent(slide);

0 commit comments

Comments
 (0)