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 {
1515}
1616
1717const 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)
18 const parent = props.sites.map((_, i) => i)
19 function find(i: number): number {
20 while (parent[i] !== i) {
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)
2249 if (!group) {
23 group = { key, sites: [] }
24 map.set(key, group)
50 group = { key: `group-${root}`, sites: [] }
51 map.set(root, group)
2552 }
2653 group.sites.push(site)
27 }
54 })
2855 return [...map.values()]
2956})
3057
docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue +14 −2
@@ -16,6 +16,18 @@ defineEmits<{
1616const primary = computed(() => props.sites[0])
1717const highestRated = computed(() => props.sites.find(site => site.rating === 'nsfw')
1818 ?? 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})
1931</script>
2032
2133<template>
@@ -24,12 +36,12 @@ const highestRated = computed(() => props.sites.find(site => site.rating === 'ns
2436 class="ext-site-cell ext-site-group"
2537 :class="{ 'ext-site-group-active': open }"
2638 :aria-expanded="open"
27 :aria-label="`${primary.name}, ${sites.length} languages`"
39 :aria-label="`${groupName}, ${sites.length} languages`"
2840 @click="$emit('toggle')"
2941 >
3042 <div class="ext-site-row">
3143 <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>
3345 <span
3446 v-if="highestRated"
3547 class="ext-site-nsfw"