Skip to content

Commit 1729d79

Browse files
committed
Update call sites after refactor to new collection schema regarding cover images
1 parent 9369da4 commit 1729d79

50 files changed

Lines changed: 389 additions & 616 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/components/Carousel/client/__fixtures__/collection.fixture.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,55 @@
1+
import type { ImageMetadata } from 'astro'
2+
3+
const createCover = (src: string, format: ImageMetadata['format'] = 'jpeg'): ImageMetadata => ({
4+
src,
5+
width: 1200,
6+
height: 675,
7+
format,
8+
})
9+
110
const sampleCollection = [
211
{
312
id: 'article-one',
413
data: {
514
title: 'Article One',
615
description: 'First test entry',
7-
publishDate: '2024-01-01',
16+
publishDate: new Date('2024-01-01'),
817
featured: true,
9-
icon: '/icons/one.svg',
18+
cover: createCover('/_astro/article-one.jpg'),
19+
coverAlt: 'Cover image for Article One',
1020
},
1121
},
1222
{
1323
id: 'article-two',
1424
data: {
1525
title: 'Article Two',
1626
description: 'Second test entry',
17-
publishDate: '2024-02-01',
27+
publishDate: new Date('2024-02-01'),
1828
featured: true,
29+
cover: createCover('/_astro/article-two.jpg'),
30+
coverAlt: 'Cover image for Article Two',
1931
},
2032
},
2133
{
2234
id: 'article-three',
2335
data: {
2436
title: 'Article Three',
2537
description: 'Third test entry',
26-
publishDate: '2024-03-01',
38+
publishDate: new Date('2024-03-01'),
2739
featured: false,
40+
cover: createCover('/_astro/article-three.jpg'),
41+
coverAlt: 'Cover image for Article Three',
2842
},
2943
},
3044
{
3145
id: 'article-four',
3246
data: {
3347
title: 'Article Four',
3448
description: 'Fourth test entry',
35-
publishDate: '2024-04-01',
49+
publishDate: new Date('2024-04-01'),
3650
featured: false,
51+
cover: createCover('/_astro/article-four.jpg'),
52+
coverAlt: 'Cover image for Article Four',
3753
},
3854
},
3955
]

src/components/Carousel/client/__tests__/index.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ describe('Carousel component (server output)', () => {
142142
const cardWithIcon = root.querySelector('[data-carousel-slide] img')
143143

144144
expect(cardWithIcon).toBeTruthy()
145-
expect(cardWithIcon?.getAttribute('src')).toBe('/icons/one.svg')
145+
expect(cardWithIcon?.getAttribute('src')).toMatch(/^\/_image\?href=/)
146+
expect(cardWithIcon?.getAttribute('alt')).toBe('Cover image for Article One')
146147
})
147148
})
148149

src/components/Carousel/index.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import { Picture } from 'astro:assets'
66
import { getCollection } from 'astro:content'
7-
// type CollectionEntry
7+
88
import {
99
type CollectionSlug,
1010
type CarouselVariant,
@@ -56,11 +56,11 @@ const items = prepareItems(allItems, variant, currentSlug, limit)
5656
href={`/${type}/${item.id}`}
5757
class="block h-full bg-bg rounded-xl shadow-lg hover:shadow-xl transition-all duration-300 overflow-hidden border border-border hover:border-primary transform hover:-translate-y-2"
5858
>
59-
{item.data.cover?.src && (
59+
{item.data.cover && (
6060
<div class="relative aspect-video overflow-hidden">
6161
<Picture
62-
src={item.data.cover.src}
63-
alt={item.data.cover.alt || item.data.title}
62+
src={item.data.cover}
63+
alt={item.data.coverAlt}
6464
widths={[320, 640, 960, 1280]}
6565
sizes="(min-width: 1024px) 33vw, (min-width: 768px) 50vw, 100vw"
6666
formats={['avif', 'webp', 'jpeg']}

0 commit comments

Comments
 (0)