From 8efb364671aa88747e27c10ba8d6df8019b805a6 Mon Sep 17 00:00:00 2001 From: Salam-vsem Date: Tue, 13 May 2025 18:27:04 +0300 Subject: [PATCH] optimize images --- src/components/Reviews.tsx | 8 +++++++- src/components/swiper/Swiper.tsx | 12 ++++++++---- src/pages/index.astro | 17 ++++++++++------- 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/components/Reviews.tsx b/src/components/Reviews.tsx index 6675e6e..167aa61 100644 --- a/src/components/Reviews.tsx +++ b/src/components/Reviews.tsx @@ -41,7 +41,13 @@ export const Reviews: React.FC = ({ reviews, lang }) => {
{[...Array(5)].map((_, i) => ( - star + star ))}
diff --git a/src/components/swiper/Swiper.tsx b/src/components/swiper/Swiper.tsx index 15097e8..c1b4f10 100644 --- a/src/components/swiper/Swiper.tsx +++ b/src/components/swiper/Swiper.tsx @@ -1,5 +1,5 @@ -import React, { useCallback, useMemo, useRef } from 'react' -import { Swiper as SwiperBase, type SwiperRef, SwiperSlide } from 'swiper/react' +import React from 'react' +import { Swiper as SwiperBase, SwiperSlide } from 'swiper/react' import { A11y, Navigation, Pagination } from 'swiper/modules' import { cn } from '@/libs/cn' import 'swiper/css' @@ -7,9 +7,10 @@ import 'swiper/css/navigation' import 'swiper/css/pagination' import './styles.css' import { NextButton, PrevButton } from './NavButtons' +import type { GetImageResult } from 'astro' type SwiperProps = { - images: (ImageMetadata & { alt: string })[] + images: GetImageResult[] className?: string } @@ -26,8 +27,11 @@ export const Swiper: React.FC = ({ images, className }) => { {images.map((image, index) => ( diff --git a/src/pages/index.astro b/src/pages/index.astro index 6af55f5..60d6fae 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -13,14 +13,21 @@ import CoachCard from '@/components/CoachCard.astro' import ServiceCard from '@/components/ServiceCard.astro' import Marquee from '@/components/Marquee.astro' import { Reviews } from '@/components/Reviews.tsx' -import { Image } from 'astro:assets' import Hero from '@/components/Hero.astro' +import { getImage } from 'astro:assets' type Props = CollectionEntry<'pages'>['data'] const { lang } = Astro.params const page = await getEntry('pages', 'main') const { slider, coaches, services, hero, marquee, reviews } = page?.data || {} +const optimizedSlider = slider + ? await Promise.all( + slider.map((slide) => + getImage({ src: slide.image, alt: slide.imageAlt, widths: [600, 800, 1200], quality: 90 }) + ) + ) + : undefined const t = useTranslations(lang) --- @@ -50,7 +57,7 @@ const t = useTranslations(lang) } { - slider && ( + optimizedSlider && (
- ({ ...image, alt: imageAlt }))} - /> +
)