Skip to content

Commit c1accdb

Browse files
committed
redesign hpme page
1 parent e60d47a commit c1accdb

12 files changed

Lines changed: 1896 additions & 621 deletions

File tree

docs/.vitepress/theme/MyLayout.vue

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
<script setup>
2+
import { useData } from 'vitepress'
23
import Theme from 'vitepress/theme'
3-
import Contributors from "./components/Contributors.vue";
4+
import HomePage from "./components/HomePage.vue";
45
56
const { Layout } = Theme
7+
const { frontmatter } = useData()
68
</script>
79

810
<template>
911
<Layout>
10-
<template #home-features-after>
11-
<div
12-
class="flex flex-col justify-center items-center w-full mt-10"
13-
>
14-
<h3 class="text-4xl! font-semibold! text-center mb-4">Contributors</h3>
15-
<Contributors />
16-
</div>
12+
<template #home-hero-before>
13+
<HomePage v-if="frontmatter.customHome" />
1714
</template>
1815
</Layout>
19-
</template>
16+
</template>
17+
18+
<style>
19+
/* Hide default VitePress home content when using custom homepage */
20+
.VPHome:has(+ .home-page),
21+
.VPHome .VPHero,
22+
.VPHome .VPFeatures {
23+
display: none !important;
24+
}
25+
26+
/* When custom home is active, hide the default home layout elements */
27+
[data-custom-home="true"] .VPHome > *:not(.home-page) {
28+
display: none !important;
29+
}
30+
</style>

docs/.vitepress/theme/components/Contributors.vue

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,64 @@ import { ref, onMounted } from 'vue'
33
44
const contributors = ref<any[]>([])
55
6+
const CACHE_KEY = 'tweakphp_contributors'
7+
const CACHE_DURATION = 60 * 60 * 1000 // 1 hour in milliseconds
8+
69
const fromRepo = (repo: string) =>
710
fetch(`https://api.github.com/repos/tweakphp/${repo}/contributors`)
811
.then((res) => res.json())
912
.catch(() => [])
1013
14+
const getCachedData = () => {
15+
if (typeof localStorage === 'undefined') return null
16+
17+
try {
18+
const cached = localStorage.getItem(CACHE_KEY)
19+
if (!cached) return null
20+
21+
const { data, timestamp } = JSON.parse(cached)
22+
const now = Date.now()
23+
24+
if (now - timestamp < CACHE_DURATION) {
25+
return data
26+
}
27+
28+
localStorage.removeItem(CACHE_KEY)
29+
return null
30+
} catch {
31+
return null
32+
}
33+
}
34+
35+
const setCachedData = (data: any[]) => {
36+
if (typeof localStorage === 'undefined') return
37+
38+
try {
39+
localStorage.setItem(CACHE_KEY, JSON.stringify({
40+
data,
41+
timestamp: Date.now()
42+
}))
43+
} catch {
44+
// Ignore storage errors
45+
}
46+
}
47+
1148
const getContributors = async () => {
49+
const cached = getCachedData()
50+
51+
if (cached) {
52+
contributors.value = cached
53+
return
54+
}
55+
1256
const users = await Promise.all([
1357
fromRepo('tweakphp'),
1458
fromRepo('docs'),
1559
fromRepo('client'),
1660
fromRepo('.github'),
1761
])
1862
19-
contributors.value = users
63+
const result = users
2064
.reduce((acc, data = []) => {
2165
if (!Array.isArray(data)) return acc
2266
return [...acc, ...data.filter(i => i.login)]
@@ -34,6 +78,9 @@ const getContributors = async () => {
3478
avatar_url: user.avatar_url
3579
}]
3680
}, [])
81+
82+
contributors.value = result
83+
setCachedData(result)
3784
}
3885
3986
onMounted(() => {

0 commit comments

Comments
 (0)