Commit 9aff1ce33a

9aff1ce33aeb16d3ae66d02d110294e24445824b

parent: 9c1cb0a4e5

Unsigned

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

improve grouping logic

Layout: unified · split

docs/.vitepress/theme/components/extrepo/SiteGrid.vue +34 −7
@@ -15,16 +15,43 @@ interface SiteGroup {
15} 15}
16 16
17const groups = computed<SiteGroup[]>(() => { 17const groups = computed<SiteGroup[]>(() => {
18 const map = new Map<string, SiteGroup>() 18 const parent = props.sites.map((_, i) => i)
19 for (const site of props.sites) { 19 function find(i: number): number {
20 const key = `${site.repoName ?? ''}-${site.name}` 20 while (parent[i] !== i) {
21 let group = map.get(key) 21 parent[i] = parent[parent[i]]
22 i = parent[i]
23 }
24 return i
25 }
26 function union(a: number, b: number) {
27 const rootA = find(a)
28 const rootB = find(b)
29 if (rootA !== rootB) parent[rootA] = rootB
30 }
31
32 const byName = new Map<string, number>()
33 const byUrl = new Map<string, number>()
34 props.sites.forEach((site, i) => {
35 const scope = site.repoName ?? ''
36 const nameKey = `${scope}-${site.name}`
37 if (byName.has(nameKey)) union(i, byName.get(nameKey)!)
38 else byName.set(nameKey, i)
39
40 const urlKey = `${scope}-${site.url}`
41 if (byUrl.has(urlKey)) union(i, byUrl.get(urlKey)!)
42 else byUrl.set(urlKey, i)
43 })
44
45 const map = new Map<number, SiteGroup>()
46 props.sites.forEach((site, i) => {
47 const root = find(i)
48 let group = map.get(root)
22 if (!group) { 49 if (!group) {
23 group = { key, sites: [] } 50 group = { key: `group-${root}`, sites: [] }
24 map.set(key, group) 51 map.set(root, group)
25 } 52 }
26 group.sites.push(site) 53 group.sites.push(site)
27 } 54 })
28 return [...map.values()] 55 return [...map.values()]
29}) 56})
30 57
docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue +14 −2
@@ -16,6 +16,18 @@ defineEmits<{
16const primary = computed(() => props.sites[0]) 16const primary = computed(() => props.sites[0])
17const highestRated = computed(() => props.sites.find(site => site.rating === 'nsfw') 17const highestRated = computed(() => props.sites.find(site => site.rating === 'nsfw')
18 ?? props.sites.find(site => site.rating === 'suggestive')) 18 ?? props.sites.find(site => site.rating === 'suggestive'))
19
20const groupName = computed(() => {
21 const wordLists = props.sites.map(site => site.name.trim().split(/\s+/))
22 const minLen = Math.min(...wordLists.map(words => words.length))
23 const common: string[] = []
24 for (let i = 0; i < minLen; i++) {
25 const word = wordLists[0][i]
26 if (wordLists.every(words => words[i] === word)) common.push(word)
27 else break
28 }
29 return common.length > 0 ? common.join(' ') : primary.value.name
30})
19</script> 31</script>
20 32
21<template> 33<template>
@@ -24,12 +36,12 @@ const highestRated = computed(() => props.sites.find(site => site.rating === 'ns
24 class="ext-site-cell ext-site-group" 36 class="ext-site-cell ext-site-group"
25 :class="{ 'ext-site-group-active': open }" 37 :class="{ 'ext-site-group-active': open }"
26 :aria-expanded="open" 38 :aria-expanded="open"
27 :aria-label="`${primary.name}, ${sites.length} languages`" 39 :aria-label="`${groupName}, ${sites.length} languages`"
28 @click="$emit('toggle')" 40 @click="$emit('toggle')"
29 > 41 >
30 <div class="ext-site-row"> 42 <div class="ext-site-row">
31 <LazyIcon class="ext-site-icon" :src="primary.icon" :alt="primary.name" /> 43 <LazyIcon class="ext-site-icon" :src="primary.icon" :alt="primary.name" />
32 <span class="ext-site-name-text" :title="primary.name">{{ primary.name }}</span> 44 <span class="ext-site-name-text" :title="groupName">{{ groupName }}</span>
33 <span 45 <span
34 v-if="highestRated" 46 v-if="highestRated"
35 class="ext-site-nsfw" 47 class="ext-site-nsfw"