Commit 70f1c357bc
Unsigned
Layout: unified · split
docs/.vitepress/theme/components/extrepo/SiteGrid.vue +5 −32
| @@ -15,40 +15,13 @@ interface SiteGroup { | |||
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | const groups = computed<SiteGroup[]>(() => { | 17 | const groups = computed<SiteGroup[]>(() => { |
| 18 | const parent = props.sites.map((_, i) => i) | 18 | const map = new Map<string, SiteGroup>() |
| 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) => { | 19 | props.sites.forEach((site, i) => { |
| 47 | const root = find(i) | 20 | const key = site.url ? `${site.repoName ?? ''}-${site.url}` : `no-url-${i}` |
| 48 | let group = map.get(root) | 21 | let group = map.get(key) |
| 49 | if (!group) { | 22 | if (!group) { |
| 50 | group = { key: `group-${root}`, sites: [] } | 23 | group = { key, sites: [] } |
| 51 | map.set(root, group) | 24 | map.set(key, group) |
| 52 | } | 25 | } |
| 53 | group.sites.push(site) | 26 | group.sites.push(site) |
| 54 | }) | 27 | }) |
docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue +7 −3
| @@ -1,6 +1,6 @@ | |||
| 1 | <script setup lang="ts"> | 1 | <script setup lang="ts"> |
| 2 | import { computed } from 'vue' | 2 | import { computed } from 'vue' |
| 3 | import { ratingIcon, ratingTitle } from './helpers' | 3 | import { langLabel, ratingIcon, ratingTitle } from './helpers' |
| 4 | import LazyIcon from './LazyIcon.vue' | 4 | import LazyIcon from './LazyIcon.vue' |
| 5 | import type { RepoSite } from './types' | 5 | import type { RepoSite } from './types' |
| 6 | 6 | ||
| @@ -26,7 +26,11 @@ const groupName = computed(() => { | |||
| 26 | if (wordLists.every(words => words[i] === word)) common.push(word) | 26 | if (wordLists.every(words => words[i] === word)) common.push(word) |
| 27 | else break | 27 | else break |
| 28 | } | 28 | } |
| 29 | return common.length > 0 ? common.join(' ') : primary.value.name | 29 | if (common.length > 0) return common.join(' ') |
| 30 | |||
| 31 | const label = langLabel(primary.value.lang) | ||
| 32 | const stripped = primary.value.name.replace(new RegExp(`\\s*${label}$`, 'i'), '').trim() | ||
| 33 | return stripped || primary.value.name | ||
| 30 | }) | 34 | }) |
| 31 | </script> | 35 | </script> |
| 32 | 36 | ||
| @@ -48,7 +52,7 @@ const groupName = computed(() => { | |||
| 48 | :class="ratingIcon(highestRated.rating)" | 52 | :class="ratingIcon(highestRated.rating)" |
| 49 | :title="ratingTitle(highestRated.rating)" | 53 | :title="ratingTitle(highestRated.rating)" |
| 50 | /> | 54 | /> |
| 51 | <span class="ext-site-layers i-lucide:layers" title="Multiple varsions available" /> | 55 | <span class="ext-site-layers i-lucide:layers" :title="`${sites.length} versions available`" /> |
| 52 | </div> | 56 | </div> |
| 53 | <span v-if="primary.repoName" class="ext-site-repo">{{ primary.repoName }}</span> | 57 | <span v-if="primary.repoName" class="ext-site-repo">{{ primary.repoName }}</span> |
| 54 | </button> | 58 | </button> |