Skip to content

Commit 6983b4c

Browse files
committed
feat(3.4): Fetch remote data + populate media page
1 parent 8ff1c5c commit 6983b4c

4 files changed

Lines changed: 80 additions & 0 deletions

File tree

‎src/components/MediaPreview.astro‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
const { post } = Astro.props
3+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', "Nov", 'Dec']
4+
---
5+
<div class="post-preview">
6+
<div class="w-32">
7+
<div class="post-preview__date">
8+
<span class="post-preview__date__day">{ new Date(post.date).getDate() }</span>
9+
<span class="post-preview__date__month-n-year">{ `${MONTHS[new Date(post.date).getMonth()]} ${new Date(post.date).getFullYear()}` }</span>
10+
</div>
11+
</div>
12+
<div class="flex-1">
13+
<div class="flex flex-col mb-2">
14+
<h4 class="post-preview__title">
15+
<a href={post.url} title={post.title} target="_blank">{post.title}</a>
16+
</h4>
17+
<div>
18+
<strong>{post.host}</strong>
19+
{
20+
post.participants.length > 0 && ` <em>with</em> ${post.participants.join(', ')}`
21+
}
22+
</div>
23+
</div>
24+
<p class="post-preview__desc">
25+
{post.description}
26+
</p>
27+
</div>
28+
</div>
29+
<style>
30+
.post-preview {
31+
@apply flex gap-6
32+
}
33+
.post-preview__date {
34+
@apply flex flex-col w-full text-center
35+
}
36+
.post-preview__date__day {
37+
@apply text-6xl font-semibold text-gray-500 dark:text-gray-300
38+
}
39+
.post-preview__date__month-n-year {
40+
@apply text-gray-400
41+
}
42+
.post-preview__title {
43+
@apply text-2xl font-semibold text-primary dark:text-primaryDark hover:underline
44+
}
45+
.post-preview__desc {
46+
@apply text-lg leading-6 dark:text-white line-clamp-2
47+
}
48+
</style>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
import MediaPreview from './MediaPreview.astro'
3+
const { posts } = Astro.props
4+
---
5+
<section class="media-preview__list">
6+
{posts.map((post) => (
7+
<MediaPreview post={post}/>
8+
))}
9+
</section>
10+
<style>
11+
.media-preview__list {
12+
@apply flex flex-col gap-12
13+
}
14+
</style>

‎src/config.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export const NAV_ITEMS: NavItems = {
99
path: '/blog',
1010
title: 'blog'
1111
},
12+
media: {
13+
path: '/media',
14+
title: 'media'
15+
},
1216
about: {
1317
path: '/about',
1418
title: 'about'

‎src/pages/media.astro‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
import DefaultPageLayout from '$/layouts/default.astro'
3+
import MediaPreviewList from '$/components/MediaPreviewList.astro'
4+
// import posts from '$/data/astro-media.json'
5+
6+
let title = 'Videos & Screencasts';
7+
let description = 'All the great videos on Astro we could find for ya!'
8+
9+
const response = await fetch('https://raw.githubusercontent.com/one-aalam/astro-ink/main/src/data/astro-media.json')
10+
const posts = await response.json()
11+
---
12+
<DefaultPageLayout content={{ title, description }}>
13+
<MediaPreviewList posts={posts} />
14+
</DefaultPageLayout>

0 commit comments

Comments
 (0)