Skip to content

Commit 448ee64

Browse files
committed
feat: Create CardLink as reusable component and improve accessibility for this card
1 parent 1518b56 commit 448ee64

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

src/components/CardLink.astro

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

src/pages/index.astro

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ 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
}
1718
18-
const shuffle = (array: string[]) => {
19+
function shuffle<T>(array: T[]): T[] {
1920
for (let i = array.length - 1; i > 0; i--) {
2021
const j = Math.floor(Math.random() * (i + 1));
2122
[array[i], array[j]] = [array[j], array[i]];
@@ -40,12 +41,7 @@ const shuffle = (array: string[]) => {
4041
{
4142
shuffle(projects).slice(0, 6).map((x) => {
4243
return (
43-
<a class="project-card group" href={x.repo}>
44-
<div class="grid gap-2">
45-
<h3 class="text-2xl font-medium transition-all">{x.name}</h3>
46-
<p class="text-base">{x.description}</p>
47-
</div>
48-
</a>
44+
<CardLink title={x.name} url={x.repo} description={x.description} />
4945
)
5046
})
5147
}

src/pages/ring.astro

Lines changed: 4 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,15 +20,9 @@ for (const project of generatedRing.projects) {
2020
<!-- TODO: languages should display as tags -->
2121
<div class="main-grid">
2222
{
23-
projects.map((project) => {
23+
projects.map(({ name, repo, description, languages }) => {
2424
return (
25-
<a class="project-card group" href={project.repo}>
26-
<div class="grid gap-1">
27-
<h3 class="text-2xl font-medium transition-all">{project.name}</h3>
28-
<p class="text-base">{project.description}</p>
29-
{project.languages && <p>{project.languages?.join(', ')}</p>}
30-
</div>
31-
</a>
25+
<CardLink title={name} url={repo} description={description} languages={languages} />
3226
)
3327
})
3428
}

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)