Commit 503394bd7c

503394bd7cbdd7b2d784abced8eb2373068f14e8

parent: 0486f43b93

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-07-13 11:13 UTC

site group

Layout: unified · split

docs/.vitepress/theme/components/extrepo/SiteGrid.vue +44 −2
@@ -1,11 +1,41 @@
11<script setup lang="ts">
2import { computed, ref } from 'vue'
23import SiteCell from './SiteCell.vue'
4import SiteGroupCell from './SiteGroupCell.vue'
35import type { RepoSite } from './types'
46
5defineProps<{
7const props = defineProps<{
68 sites: (RepoSite & { repoName?: string })[]
79 emptyText: string
810}>()
11
12interface SiteGroup {
13 key: string
14 sites: (RepoSite & { repoName?: string })[]
15}
16
17const groups = computed<SiteGroup[]>(() => {
18 const map = new Map<string, SiteGroup>()
19 for (const site of props.sites) {
20 const key = `${site.repoName ?? ''}-${site.name}`
21 let group = map.get(key)
22 if (!group) {
23 group = { key, sites: [] }
24 map.set(key, group)
25 }
26 group.sites.push(site)
27 }
28 return [...map.values()]
29})
30
31const openGroups = ref<Set<string>>(new Set())
32
33function toggleGroup(key: string) {
34 const next = new Set(openGroups.value)
35 if (next.has(key)) next.delete(key)
36 else next.add(key)
37 openGroups.value = next
38}
939</script>
1040
1141<template>
@@ -13,7 +43,19 @@ defineProps<{
1343 <div v-if="sites.length === 0" class="ext-site-empty">
1444 {{ emptyText }}
1545 </div>
16 <SiteCell v-for="site in sites" :key="`${site.repoName ?? ''}-${site.name}-${site.lang}`" :site="site" />
46 <template v-for="group in groups" :key="group.key">
47 <SiteCell v-if="group.sites.length === 1" :site="group.sites[0]" />
48 <template v-else>
49 <SiteGroupCell
50 :sites="group.sites"
51 :open="openGroups.has(group.key)"
52 @toggle="toggleGroup(group.key)"
53 />
54 <template v-if="openGroups.has(group.key)">
55 <SiteCell v-for="site in group.sites" :key="`${group.key}-${site.lang}`" :site="site" />
56 </template>
57 </template>
58 </template>
1759 </div>
1860</template>
1961
docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue added +128
@@ -0,0 +1,128 @@
1<script setup lang="ts">
2import { computed } from 'vue'
3import { ratingIcon, ratingTitle } from './helpers'
4import type { RepoSite } from './types'
5
6const props = defineProps<{
7 sites: (RepoSite & { repoName?: string })[]
8 open: boolean
9}>()
10
11defineEmits<{
12 toggle: []
13}>()
14
15const primary = computed(() => props.sites[0])
16const highestRated = computed(() => props.sites.find(site => site.rating === 'nsfw')
17 ?? props.sites.find(site => site.rating === 'suggestive'))
18</script>
19
20<template>
21 <button
22 type="button"
23 class="ext-site-cell ext-site-group"
24 :class="{ 'ext-site-group-active': open }"
25 :aria-expanded="open"
26 :aria-label="`${primary.name}, ${sites.length} languages`"
27 @click="$emit('toggle')"
28 >
29 <div class="ext-site-row">
30 <img v-if="primary.icon" class="ext-site-icon" :src="primary.icon" :alt="primary.name" loading="lazy" />
31 <span v-else class="ext-site-icon ext-site-icon-fallback i-lucide:globe" />
32 <span class="ext-site-name-text">{{ primary.name }}</span>
33 <span
34 v-if="highestRated"
35 class="ext-site-nsfw"
36 :class="ratingIcon(highestRated.rating)"
37 :title="ratingTitle(highestRated.rating)"
38 />
39 <span class="ext-site-layers i-lucide:layers" title="Multiple languages available" />
40 </div>
41 <span v-if="primary.repoName" class="ext-site-repo">{{ primary.repoName }}</span>
42 </button>
43</template>
44
45<style scoped>
46.ext-site-cell {
47 display: flex;
48 flex-direction: column;
49 gap: 0;
50 padding: 6px 8px;
51 border-radius: 6px;
52 border: 1px solid var(--vp-c-divider);
53 background-color: var(--vp-c-bg-soft);
54 min-width: 0;
55 color: var(--vp-c-text-1) !important;
56 text-decoration: none !important;
57 transition: border-color 0.2s, background-color 0.2s;
58}
59
60.ext-site-group {
61 width: 100%;
62 font: inherit;
63 text-align: left;
64 cursor: pointer;
65}
66
67.ext-site-group:hover,
68.ext-site-group-active {
69 border-color: var(--vp-c-brand-1);
70 background-color: var(--vp-c-bg);
71}
72
73.ext-site-row {
74 display: flex;
75 align-items: center;
76 gap: 6px;
77 min-width: 0;
78}
79
80.ext-site-icon {
81 width: 18px;
82 height: 18px;
83 border-radius: 4px;
84 flex-shrink: 0;
85 object-fit: contain;
86}
87
88.ext-site-icon-fallback {
89 display: flex;
90 align-items: center;
91 justify-content: center;
92 color: var(--vp-c-text-3);
93}
94
95.ext-site-name-text {
96 flex: 1;
97 min-width: 0;
98 font-size: 12.5px;
99 font-weight: 600;
100 line-height: 1.2;
101 color: var(--vp-c-text-1);
102 white-space: nowrap;
103 overflow: hidden;
104 text-overflow: ellipsis;
105}
106
107.ext-site-nsfw,
108.ext-site-layers {
109 flex-shrink: 0;
110 font-size: 12px;
111}
112
113.ext-site-layers {
114 color: var(--vp-c-brand-1);
115}
116
117.ext-site-repo {
118 display: block;
119 padding-left: 24px;
120 font-size: 10.5px;
121 font-weight: 400;
122 line-height: 1.1;
123 color: var(--vp-c-text-2);
124 white-space: nowrap;
125 overflow: hidden;
126 text-overflow: ellipsis;
127}
128</style>