Skip to content

Commit d0f0b53

Browse files
committed
feat: Create CardLink as reusable component and improve accessibility for this card
1 parent 56091c9 commit d0f0b53

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

src/components/CardLink.astro

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
import type { HTMLAttributes } from 'astro/types'
3+
4+
interface Props {
5+
title: string
6+
url: string
7+
description: string
8+
}
9+
const { title, url, description } = Astro.props
10+
---
11+
12+
<div class="project-card group relative">
13+
<div class="grid gap-1">
14+
<a href={url} class="after:absolute after:inset-0 after:content-['']">
15+
<h3 class="text-2xl font-medium transition-all">
16+
{title}
17+
</h3>
18+
</a>
19+
<p class="text-base">
20+
{description}
21+
</p>
22+
</div>
23+
</div>

src/pages/index.astro

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ import ring from '../content/ring.json'
44
import generatedRing from '../content/ring.generated.json'
55
import events from '../content/events.json'
66
import sponsors from '../content/sponsors.json'
7+
import CardLink from '../components/CardLink.astro'
78
89
// TODO: refactor dedupe logic to separate file?
910
// TODO: limit projects in index page
1011
const projects = [...ring.projects]
11-
for (const project of generatedRing.projects) {
12+
for (const project of generatedRing.projects as typeof ring.projects) {
1213
const index = projects.findIndex((x) => x.name === project.name)
1314
if (index === -1) {
1415
projects.push(project)
1516
}
1617
}
17-
1818
---
1919

2020
<BaseLayout>
@@ -32,12 +32,7 @@ for (const project of generatedRing.projects) {
3232
{
3333
projects.map((x) => {
3434
return (
35-
<a class="project-card group" href={x.repo}>
36-
<div class="grid gap-1">
37-
<h3 class="text-2xl font-medium transition-all">{x.name}</h3>
38-
<p class="text-base">{x.description}</p>
39-
</div>
40-
</a>
35+
<CardLink title={x.name} url={x.repo} description={x.description} />
4136
)
4237
})
4338
}

src/pages/ring.astro

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
import BaseLayout from '../layouts/BaseLayout.astro'
33
import ring from '../content/ring.json'
44
import generatedRing from '../content/ring.generated.json'
5+
import CardLink from '../components/CardLink.astro'
56
67
// TODO: refactor dedupe logic to separate file?
78
const projects = [...ring.projects]
8-
for (const project of generatedRing.projects) {
9+
for (const project of generatedRing.projects as typeof ring.projects) {
910
const index = projects.findIndex((x) => x.name === project.name)
1011
if (index === -1) {
1112
projects.push(project)
1213
}
1314
}
14-
1515
---
1616

1717
<BaseLayout>
@@ -20,14 +20,7 @@ for (const project of generatedRing.projects) {
2020
<div class="main-grid">
2121
{
2222
projects.map((x) => {
23-
return (
24-
<a class="project-card group" href={x.repo}>
25-
<div class="grid gap-1">
26-
<h3 class="text-2xl font-medium transition-all">{x.name}</h3>
27-
<p class="text-base">{x.description}</p>
28-
</div>
29-
</a>
30-
)
23+
return <CardLink title={x.name} url={x.repo} description={x.description} />
3124
})
3225
}
3326
</div>

src/styles/global.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ a {
2929
@apply rounded-full bg-gradient-to-br from-neutral-800 to-neutral-900 px-6 py-3 text-xl text-neutral-50 shadow-sm transition-all hover:scale-[1.02] hover:text-neutral-50 hover:shadow-md;
3030
}
3131

32-
.project-card {
32+
.card-card {
3333
@apply flex flex-col gap-4 rounded-sm border border-bosf/30 bg-white p-6 shadow-sm transition-all hover:scale-[1.01] hover:border-bosf/50 hover:bg-gradient-to-br;
3434
}

0 commit comments

Comments
 (0)