-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathSponsors.astro
105 lines (95 loc) · 2.5 KB
/
Sponsors.astro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
/**
* Component for displaying GitHub sponsors, used on the homepage
* and Support DDEV page.
*
* Featured sponsors can optionally be included.
*/
import { getSponsors } from "../lib/api"
import { Image } from 'astro:assets';
import featuredSponsors from "../featured-sponsors.json"
export interface Props {
size?: "normal" | "large"
align?: string
includeFeatured?: boolean
}
export interface Sponsor {
title: string
url: string
imageUrl: string
imageAlt: string
}
const { size = "normal", align = "left", includeFeatured = false } = Astro.props
let sponsors: Sponsor[] = []
let gitHubHandles = []
// Fetch GitHub sponsors
const gitHubSponsors = await getSponsors()
if (includeFeatured) {
/**
* Pull featured sponsors into the front of the list
* and make sure they’re not duplicated
*/
featuredSponsors.forEach((featuredSponsor) => {
sponsors.push({
title: featuredSponsor.name,
url: featuredSponsor.url,
imageUrl: featuredSponsor.squareLogo,
imageAlt: `${featuredSponsor.name} logo`,
})
if (featuredSponsor.github) {
gitHubHandles.push(featuredSponsor.github.toLowerCase())
}
})
}
gitHubSponsors.forEach((gitHubSponsor) => {
if (gitHubHandles.includes(gitHubSponsor.login.toLowerCase())) {
// Don’t duplicate listings
return
}
sponsors.push({
title: gitHubSponsor.login,
url: gitHubSponsor.url,
imageUrl: gitHubSponsor.avatarUrl,
imageAlt: `${gitHubSponsor.login} GitHub avatar`,
})
})
---
<div class="relative">
<div
class={`flex flex-wrap -mx-1` +
(align == "center" ? " justify-center" : "")}
>
{
sponsors.map((sponsor) => (
<a
class={
`block rounded-full relative overflow-hidden m-1 shadow-md ` +
(size == "large" ? `w-12 h-12` : `w-8 h-8`)
}
title={sponsor.title}
href={sponsor.url}
target="_blank"
>
{sponsor.imageUrl.includes(".svg") && (
<img
src={sponsor.imageUrl}
alt={sponsor.imageAlt}
width={100}
height={100}
class={`block w-full h-full dark:bg-white`}
/>
)}
{!sponsor.imageUrl.includes(".svg") && (
<Image
src={sponsor.imageUrl}
alt={sponsor.imageAlt}
width={100}
height={100}
class="block w-full h-full dark:bg-white"
/>
)}
</a>
))
}
</div>
</div>