Skip to content

Commit 6778ed4

Browse files
feat: Cluster trailers by year (#130)
Cluster the different trailers by year based on the date manually added to each entry
1 parent 02df633 commit 6778ed4

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

src/components/Community.astro

+28-13
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,34 @@ import { community_videos } from "../data/community-videos.ts";
55

66
<div class="community-videos">
77
{
8-
community_videos.map((item) => (
9-
<div class="video-item">
10-
{/* <span class="comment">{item.comment}</span> */}
11-
{/* <span class="creator">{item.creator}</span> */}
12-
<iframe
13-
class="community-video-youtube-iframe"
14-
src={`https://www.youtube-nocookie.com/embed/${item.youtube_id}`}
15-
title="YouTube video player"
16-
frameborder="0"
17-
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
18-
referrerpolicy="strict-origin-when-cross-origin"
19-
allowfullscreen
20-
/>
8+
Object.entries(
9+
community_videos.reduce(
10+
(acc: { [key: number]: typeof community_videos }, item) => {
11+
const year = new Date(item.date).getFullYear();
12+
if (!acc[year]) acc[year] = [];
13+
acc[year].push(item);
14+
return acc;
15+
},
16+
{},
17+
),
18+
).map(([year, videos]) => (
19+
<div class="year-group">
20+
<h2>{year}</h2>
21+
{videos.map((item) => (
22+
<div class="video-item">
23+
{/* <span class="comment">{item.comment}</span> */}
24+
{/* <span class="creator">{item.creator}</span> */}
25+
<iframe
26+
class="community-video-youtube-iframe"
27+
src={`https://www.youtube-nocookie.com/embed/${item.youtube_id}`}
28+
title="YouTube video player"
29+
frameborder="0"
30+
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
31+
referrerpolicy="strict-origin-when-cross-origin"
32+
allowfullscreen
33+
/>
34+
</div>
35+
))}
2136
</div>
2237
))
2338
}

0 commit comments

Comments
 (0)