-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsponsor.ts
61 lines (51 loc) · 1.06 KB
/
sponsor.ts
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
import { ref, onMounted } from 'vue'
interface Sponsors {
special: Sponsor[]
platinum: Sponsor[]
platinum_china: Sponsor[]
gold: Sponsor[]
silver: Sponsor[]
bronze: Sponsor[]
}
interface Sponsor {
name: string
img: string
url: string
}
// shared data across instances so we load only once.
const data = ref()
const dataHost = 'https://sponsors.vuejs.org'
const dataUrl = `${dataHost}/vite.json`
export function useSponsor() {
onMounted(async () => {
if (data.value) {
return
}
const result = await fetch(dataUrl)
const json = await result.json()
data.value = mapSponsors(json)
})
return {
data
}
}
function mapSponsors(sponsors: Sponsors) {
return [
{
tier: 'Platinum Sponsor',
size: 'big',
items: mapImgPath(sponsors['platinum'])
},
{
tier: 'Gold Sponsors',
size: 'medium',
items: mapImgPath(sponsors['gold'])
}
]
}
function mapImgPath(sponsors: Sponsor[]) {
return sponsors.map((sponsor) => ({
...sponsor,
img: `${dataHost}/images/${sponsor.img}`
}))
}