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