docs/.vitepress/theme/components/extrepo/ExtensionRepos.vue
155 lines · 4873 bytes
1<script setup lang="ts">
2import { computed, ref } from 'vue'
3import { data as repoData } from '../../../../ext/extensionRepos.data'
4import { langLabel, stripHtml } from './helpers'
5import { mangayomiCopyValue } from './install'
6import RepoRow from './RepoRow.vue'
7import SettingsMenu from './SettingsMenu.vue'
8import SiteGrid from './SiteGrid.vue'
9import type { MatchedSite, RatingFilter, Repo } from './types'
10
11const props = defineProps<{
12 repos: Repo[]
13 scheme: string
14}>()
15
16const query = ref('')
17const langFilter = ref('')
18const ratingFilter = ref<RatingFilter>('all')
19const excludedContentTypes = ref<Set<string>>(new Set())
20const showBroken = ref(false)
21
22const allSites = computed<MatchedSite[]>(() => {
23 const sites: MatchedSite[] = []
24 for (const repo of props.repos) {
25 if (repo.variants?.length) {
26 // search fix for variations of setup. (mangayomi and kotatsu)
27 const sameRepoName = repo.repoName ? stripHtml(repo.name) : undefined
28 for (const variant of repo.variants) {
29 const url = mangayomiCopyValue(variant)
30 if (!url) continue
31 const repoName = sameRepoName ?? variant.label
32 for (const site of repoData[url]?.sites ?? []) {
33 sites.push({ ...site, repoName })
34 }
35 }
36 continue
37 }
38 const repoName = stripHtml(repo.name)
39 for (const site of repoData[repo.indexUrl]?.sites ?? []) {
40 sites.push({ ...site, repoName })
41 }
42 }
43 return sites
44})
45
46const availableContentTypes = computed(() => {
47 const types = new Set<string>()
48 for (const site of allSites.value) if (site.contentType) types.add(site.contentType)
49 return [...types].sort()
50})
51const hasContentTypes = computed(() => availableContentTypes.value.length > 0)
52
53const hasRatings = computed(() => allSites.value.some(site => site.rating !== 'safe'))
54const hasSuggestive = computed(() => allSites.value.some(site => site.rating === 'suggestive'))
55const hasMultiLanguage = computed(() => allSites.value.some(site => site.lang.toLowerCase() === 'all'))
56const hasBroken = computed(() => allSites.value.some(site => site.isBroken))
57
58const availableLangs = computed(() => {
59 const codes = new Set(allSites.value.map(site => site.lang))
60 codes.delete('all')
61 return [...codes].sort((a, b) => langLabel(a).localeCompare(langLabel(b)))
62})
63
64const isFiltering = computed(() => {
65 return query.value.trim() !== '' || langFilter.value !== '' || ratingFilter.value !== 'all' || excludedContentTypes.value.size > 0
66})
67
68const filteredSites = computed(() => {
69 const q = query.value.trim().toLowerCase()
70 return allSites.value.filter(site => {
71 if (site.isBroken && !showBroken.value) return false
72 if (q && !site.name.toLowerCase().includes(q) && !site.url.toLowerCase().includes(q)) return false
73 if (langFilter.value && site.lang !== langFilter.value) return false
74 if (ratingFilter.value !== 'all' && site.rating !== ratingFilter.value) return false
75 if (site.contentType && excludedContentTypes.value.has(site.contentType)) return false
76 return true
77 })
78})
79</script>
80
81<template>
82 <div class="ext-repos">
83 <div class="ext-toolbar">
84 <div class="ext-search">
85 <span class="i-lucide:search" />
86 <input v-model="query" type="text" placeholder="Search all sites…" />
87 </div>
88 <SettingsMenu
89 v-model:lang-filter="langFilter"
90 v-model:rating-filter="ratingFilter"
91 v-model:content-type-filter="excludedContentTypes"
92 v-model:show-broken="showBroken"
93 :available-langs="availableLangs"
94 :has-multi-language="hasMultiLanguage"
95 :has-ratings="hasRatings"
96 :has-suggestive="hasSuggestive"
97 :available-content-types="availableContentTypes"
98 :has-content-types="hasContentTypes"
99 :has-broken="hasBroken"
100 />
101 </div>
102
103 <SiteGrid
104 v-if="isFiltering"
105 class="ext-search-results"
106 :sites="filteredSites"
107 empty-text="No sites match your filters."
108 />
109
110 <div v-else>
111 <RepoRow v-for="repo in repos" :key="repo.indexUrl" :repo="repo" :scheme="scheme" :show-broken="showBroken" />
112 </div>
113 </div>
114</template>
115
116<style scoped>
117.ext-repos {
118 margin: 16px 0;
119 border: 1px solid var(--vp-c-divider);
120 border-radius: var(--radius-xl, 12px);
121 overflow: hidden;
122}
123
124.ext-toolbar {
125 display: flex;
126 flex-wrap: wrap;
127 align-items: center;
128 gap: 8px;
129 padding: 10px;
130 background-color: var(--vp-c-bg-soft);
131 border-bottom: 1px solid var(--vp-c-divider);
132}
133
134.ext-search {
135 display: flex;
136 align-items: center;
137 gap: 6px;
138 flex: 1 1 200px;
139 padding: 6px 10px;
140 border-radius: 8px;
141 border: 1px solid var(--vp-c-divider);
142 background-color: var(--vp-c-bg);
143 color: var(--vp-c-text-2);
144}
145
146.ext-search input {
147 flex: 1;
148 min-width: 0;
149 border: none;
150 outline: none;
151 background: transparent;
152 color: var(--vp-c-text-1);
153 font-size: 13px;
154}
155</style>