Commit 9aff1ce33a
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/extrepo/SiteGrid.vue +34 −7
| @@ -15,16 +15,43 @@ interface SiteGroup { | ||
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | const 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) | |
| 22 | 49 | if (!group) { |
| 23 | group = { key, sites: [] } | |
| 24 | map.set(key, group) | |
| 50 | group = { key: `group-${root}`, sites: [] } | |
| 51 | map.set(root, group) | |
| 25 | 52 | } |
| 26 | 53 | group.sites.push(site) |
| 27 | } | |
| 54 | }) | |
| 28 | 55 | return [...map.values()] |
| 29 | 56 | }) |
| 30 | 57 | |
docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue +14 −2
| @@ -16,6 +16,18 @@ defineEmits<{ | ||
| 16 | 16 | const primary = computed(() => props.sites[0]) |
| 17 | 17 | const highestRated = computed(() => props.sites.find(site => site.rating === 'nsfw') |
| 18 | 18 | ?? props.sites.find(site => site.rating === 'suggestive')) |
| 19 | ||
| 20 | const 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 | 31 | </script> |
| 20 | 32 | |
| 21 | 33 | <template> |
| @@ -24,12 +36,12 @@ const highestRated = computed(() => props.sites.find(site => site.rating === 'ns | ||
| 24 | 36 | class="ext-site-cell ext-site-group" |
| 25 | 37 | :class="{ 'ext-site-group-active': open }" |
| 26 | 38 | :aria-expanded="open" |
| 27 | :aria-label="`${primary.name}, ${sites.length} languages`" | |
| 39 | :aria-label="`${groupName}, ${sites.length} languages`" | |
| 28 | 40 | @click="$emit('toggle')" |
| 29 | 41 | > |
| 30 | 42 | <div class="ext-site-row"> |
| 31 | 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 | 45 | <span |
| 34 | 46 | v-if="highestRated" |
| 35 | 47 | class="ext-site-nsfw" |