docs/.vitepress/theme/components/extrepo/ExtensionRepos.vue
229 lines · 7403 bytes
1<script setup lang="ts">
2import { computed, ref } from 'vue'
3import { data } from '../../../../ext/extensionRepos.data'
4import { escapeHtml, 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'
10import { provideTooltip } from './useTooltip'
11
12const { tooltip } = provideTooltip()
13
14const repoData = data.sites
15const soraAuthors = data.soraAuthors
16const echoAuthors = data.echoAuthors
17
18const props = defineProps<{
19 repos: Repo[]
20 scheme: string
21}>()
22
23const resolvedRepos = computed<Repo[]>(() => {
24 const result: Repo[] = []
25 for (const repo of props.repos) {
26 const authors = soraAuthors[repo.indexUrl] ?? echoAuthors[repo.indexUrl]
27 if (!authors?.length) {
28 result.push(repo)
29 continue
30 }
31 for (const author of authors) {
32 const name = author.repoUrl
33 ? `<a href="${author.repoUrl}" target="_blank" rel="noopener noreferrer">${escapeHtml(author.label)}</a>`
34 : escapeHtml(author.label)
35 result.push({ name, indexUrl: author.indexUrl, repoName: author.label })
36 }
37 }
38 return result
39})
40
41const query = ref('')
42const langFilter = ref('')
43const ratingFilter = ref<RatingFilter>('all')
44const contentTypeFilter = ref('')
45const excludedStreamTypes = ref<Set<string>>(new Set())
46const excludedQualities = ref<Set<string>>(new Set())
47const showBroken = ref(false)
48
49const allSites = computed<MatchedSite[]>(() => {
50 const sites: MatchedSite[] = []
51 for (const repo of resolvedRepos.value) {
52 if (repo.variants?.length) {
53 // search fix for variations of setup. (mangayomi and kotatsu)
54 const sameRepoName = repo.repoName ? stripHtml(repo.name) : undefined
55 for (const variant of repo.variants) {
56 const url = mangayomiCopyValue(variant)
57 if (!url) continue
58 const repoName = sameRepoName ?? variant.label
59 for (const site of repoData[url]?.sites ?? []) {
60 sites.push({ ...site, repoName })
61 }
62 }
63 continue
64 }
65 const repoName = stripHtml(repo.name)
66 const dataUrl = repo.data ?? repo.indexUrl
67 for (const site of repoData[dataUrl]?.sites ?? []) {
68 sites.push({ ...site, repoName })
69 }
70 }
71 return sites
72})
73
74const availableContentTypes = computed(() => {
75 const types = new Set<string>()
76 for (const site of allSites.value) if (site.contentType) types.add(site.contentType)
77 return [...types].sort()
78})
79const hasContentTypes = computed(() => availableContentTypes.value.length > 0)
80
81const availableStreamTypes = computed(() => {
82 const types = new Set<string>()
83 for (const site of allSites.value) if (site.streamType) types.add(site.streamType)
84 return [...types].sort()
85})
86const hasStreamTypes = computed(() => availableStreamTypes.value.length > 0)
87
88const availableQualities = computed(() => {
89 const types = new Set<string>()
90 for (const site of allSites.value) if (site.quality) types.add(site.quality)
91 return [...types].sort()
92})
93const hasQualities = computed(() => availableQualities.value.length > 0)
94
95const hasRatings = computed(() => allSites.value.some(site => site.rating !== 'safe'))
96const hasSuggestive = computed(() => allSites.value.some(site => site.rating === 'suggestive'))
97const hasMultiLanguage = computed(() => allSites.value.some(site => site.lang.toLowerCase() === 'all'))
98const hasBroken = computed(() => allSites.value.some(site => site.isBroken))
99
100const availableLangs = computed(() => {
101 const codes = new Set(allSites.value.map(site => site.lang))
102 codes.delete('all')
103 return [...codes].sort((a, b) => langLabel(a).localeCompare(langLabel(b)))
104})
105
106const isFiltering = computed(() => {
107 return query.value.trim() !== '' || langFilter.value !== '' || ratingFilter.value !== 'all'
108 || contentTypeFilter.value !== '' || excludedStreamTypes.value.size > 0 || excludedQualities.value.size > 0
109})
110
111const filteredSites = computed(() => {
112 const q = query.value.trim().toLowerCase()
113 return allSites.value.filter(site => {
114 if (site.isBroken && !showBroken.value) return false
115 if (q && !site.name.toLowerCase().includes(q) && !site.url.toLowerCase().includes(q)) return false
116 if (langFilter.value && site.lang !== langFilter.value) return false
117 if (ratingFilter.value !== 'all' && site.rating !== ratingFilter.value) return false
118 if (contentTypeFilter.value && site.contentType !== contentTypeFilter.value) return false
119 if (site.streamType && excludedStreamTypes.value.has(site.streamType)) return false
120 if (site.quality && excludedQualities.value.has(site.quality)) return false
121 return true
122 })
123})
124</script>
125
126<template>
127 <div class="ext-repos">
128 <div class="ext-toolbar">
129 <div class="ext-search">
130 <span class="i-lucide:search" />
131 <input v-model="query" type="text" placeholder="Search all sites…" />
132 </div>
133 <SettingsMenu
134 v-model:lang-filter="langFilter"
135 v-model:rating-filter="ratingFilter"
136 v-model:content-type-filter="contentTypeFilter"
137 v-model:stream-type-filter="excludedStreamTypes"
138 v-model:quality-filter="excludedQualities"
139 v-model:show-broken="showBroken"
140 :available-langs="availableLangs"
141 :has-multi-language="hasMultiLanguage"
142 :has-ratings="hasRatings"
143 :has-suggestive="hasSuggestive"
144 :available-content-types="availableContentTypes"
145 :has-content-types="hasContentTypes"
146 :available-stream-types="availableStreamTypes"
147 :has-stream-types="hasStreamTypes"
148 :available-qualities="availableQualities"
149 :has-qualities="hasQualities"
150 :has-broken="hasBroken"
151 />
152 </div>
153
154 <SiteGrid
155 v-if="isFiltering"
156 class="ext-search-results"
157 :sites="filteredSites"
158 :scheme="scheme"
159 empty-text="No sites match your filters."
160 />
161
162 <div v-else>
163 <RepoRow v-for="repo in resolvedRepos" :key="repo.indexUrl" :repo="repo" :scheme="scheme" :show-broken="showBroken" />
164 </div>
165 </div>
166
167 <Teleport to="body">
168 <div
169 v-if="tooltip"
170 class="ext-fixed-tooltip"
171 :style="{ left: tooltip.x + 'px', top: tooltip.y + 'px' }"
172 >{{ tooltip.text }}</div>
173 </Teleport>
174</template>
175
176<style scoped>
177.ext-repos {
178 margin: 16px 0;
179 border: 1px solid var(--vp-c-divider);
180 border-radius: var(--radius-xl, 12px);
181 overflow: hidden;
182}
183
184.ext-toolbar {
185 display: flex;
186 flex-wrap: wrap;
187 align-items: center;
188 gap: 8px;
189 padding: 10px;
190 background-color: var(--vp-c-bg-soft);
191 border-bottom: 1px solid var(--vp-c-divider);
192}
193
194.ext-search {
195 display: flex;
196 align-items: center;
197 gap: 6px;
198 flex: 1 1 200px;
199 padding: 6px 10px;
200 border-radius: 8px;
201 border: 1px solid var(--vp-c-divider);
202 background-color: var(--vp-c-bg);
203 color: var(--vp-c-text-2);
204}
205
206.ext-search input {
207 flex: 1;
208 min-width: 0;
209 border: none;
210 outline: none;
211 background: transparent;
212 color: var(--vp-c-text-1);
213 font-size: 13px;
214}
215
216.ext-fixed-tooltip {
217 position: fixed;
218 z-index: 9999;
219 transform: translate(-50%, calc(-100% - 15px));
220 background: var(--vp-c-bg-soft);
221 color: var(--vp-c-text-1);
222 border: 1px solid var(--vp-c-brand-1);
223 border-radius: 5px;
224 padding: 3px 8px;
225 font-size: 11px;
226 white-space: nowrap;
227 pointer-events: none;
228}
229</style>