Commit a66ad69b50

a66ad69b5009c3d35464518c07f33994d5a7d686

parent: e8f7c44652

Unsigned

Duck <57977673+woducku@users.noreply.github.com> · 2026-10-12 14:09 UTC

a

Layout: unified · split

docs/.vitepress/configs/markdown/extRepoPlugin.ts +55 −18
@@ -40,20 +40,26 @@ interface ParsedRepoEntry {
40 builds?: ParsedRepoBuild[] 40 builds?: ParsedRepoBuild[]
41} 41}
42 42
43import { parseExtRepoAttrs } from '../../../ext/extensionRepos/attrs'
44
43// Parser 45// Parser
44 46
45function parseAttrs(info: string): Record<string, string> { 47function isManualOrder(attrs: Record<string, string>): boolean {
46 const match = info.match(/\{([^}]*)\}/) 48 if (attrs.order !== undefined) return attrs.order === 'manual'
47 if (!match) return {} 49 const manual = attrs.manual?.toLowerCase()
48 const attrs: Record<string, string> = {} 50 return manual === 'true' || manual === '1'
49 for (const pair of match[1].split(/\s+/).filter(Boolean)) {
50 const [key, value] = pair.split('=')
51 if (key && value) attrs[key] = value.replace(/^["']|["']$/g, '')
52 }
53 return attrs
54} 51}
55 52
56const FIELD_KEYS = new Set(['url', 'src', 'raw', 'note', 'manga', 'anime', 'novel', 'data']) 53const FIELD_KEYS = new Set([
54 'url',
55 'src',
56 'raw',
57 'note',
58 'manga',
59 'anime',
60 'novel',
61 'data'
62])
57 63
58function parseEntries(bodyLines: string[]): ParsedRepoEntry[] { 64function parseEntries(bodyLines: string[]): ParsedRepoEntry[] {
59 const entries: ParsedRepoEntry[] = [] 65 const entries: ParsedRepoEntry[] = []
@@ -88,7 +94,19 @@ function parseEntries(bodyLines: string[]): ParsedRepoEntry[] {
88 if (key === 'raw') currentBuild.raw = value 94 if (key === 'raw') currentBuild.raw = value
89 continue 95 continue
90 } 96 }
91 if (FIELD_KEYS.has(key)) current[key as 'url' | 'src' | 'raw' | 'note' | 'manga' | 'anime' | 'novel' | 'data'] = value 97 if (FIELD_KEYS.has(key)) {
98 current[
99 key as
100 | 'url'
101 | 'src'
102 | 'raw'
103 | 'note'
104 | 'manga'
105 | 'anime'
106 | 'novel'
107 | 'data'
108 ] = value
109 }
92 } 110 }
93 } 111 }
94 if (current) entries.push(current) 112 if (current) entries.push(current)
@@ -101,13 +119,21 @@ function nameMarkdown(entry: ParsedRepoEntry): string {
101 return entry.src ? `${label} [:src:](${entry.src})` : label 119 return entry.src ? `${label} [:src:](${entry.src})` : label
102} 120}
103 121
104function buildVariants(entry: ParsedRepoEntry): ParsedRepoVariant[] | undefined { 122function buildVariants(
105 const typeCount = [entry.manga, entry.anime, entry.novel].filter(Boolean).length 123 entry: ParsedRepoEntry
124): ParsedRepoVariant[] | undefined {
125 const typeCount =
126 [entry.manga, entry.anime, entry.novel].filter(Boolean).length
106 if (typeCount === 0) return undefined 127 if (typeCount === 0) return undefined
107 128
108 const variants: ParsedRepoVariant[] = [] 129 const variants: ParsedRepoVariant[] = []
109 if (typeCount > 1) { 130 if (typeCount > 1) {
110 variants.push({ label: 'All-in-One', mangaUrl: entry.manga, animeUrl: entry.anime, novelUrl: entry.novel }) 131 variants.push({
132 label: 'All-in-One',
133 mangaUrl: entry.manga,
134 animeUrl: entry.anime,
135 novelUrl: entry.novel
136 })
111 } 137 }
112 if (entry.manga) variants.push({ label: 'Manga', mangaUrl: entry.manga }) 138 if (entry.manga) variants.push({ label: 'Manga', mangaUrl: entry.manga })
113 if (entry.anime) variants.push({ label: 'Anime', animeUrl: entry.anime }) 139 if (entry.anime) variants.push({ label: 'Anime', animeUrl: entry.anime })
@@ -149,7 +175,10 @@ export function extRepoPlugin(md: MarkdownIt): void {
149 if (p < m && state.sCount[nextLine] < state.blkIndent) break 175 if (p < m && state.sCount[nextLine] < state.blkIndent) break
150 176
151 let cnt = 0 177 let cnt = 0
152 while (p < m && state.src[p] === MARKER) { p++; cnt++ } 178 while (p < m && state.src[p] === MARKER) {
179 p++
180 cnt++
181 }
153 if (cnt >= markerCount && state.src.slice(p, m).trim() === '') { 182 if (cnt >= markerCount && state.src.slice(p, m).trim() === '') {
154 found = true 183 found = true
155 break 184 break
@@ -162,9 +191,10 @@ export function extRepoPlugin(md: MarkdownIt): void {
162 bodyLines.push(state.src.slice(state.bMarks[i], state.eMarks[i])) 191 bodyLines.push(state.src.slice(state.bMarks[i], state.eMarks[i]))
163 } 192 }
164 193
165 const attrs = parseAttrs(params) 194 const attrs = parseExtRepoAttrs(params)
166 const scheme = attrs.scheme || 'mihon' 195 const scheme = attrs.scheme || 'mihon'
167 const from = attrs.from 196 const from = attrs.from
197 const manualAttr = isManualOrder(attrs) ? ' manual' : ''
168 198
169 const rows: ParsedRepoRow[] = [] 199 const rows: ParsedRepoRow[] = []
170 for (const entry of parseEntries(bodyLines)) { 200 for (const entry of parseEntries(bodyLines)) {
@@ -180,7 +210,13 @@ export function extRepoPlugin(md: MarkdownIt): void {
180 .filter((b): b is Required<ParsedRepoBuild> => Boolean(b.raw)) 210 .filter((b): b is Required<ParsedRepoBuild> => Boolean(b.raw))
181 .map(b => ({ label: b.label, mangaUrl: b.raw })) 211 .map(b => ({ label: b.label, mangaUrl: b.raw }))
182 if (groupVariants.length) { 212 if (groupVariants.length) {
183 rows.push({ name, indexUrl: groupVariants[0].mangaUrl!, note, data: entry.data, variants: groupVariants }) 213 rows.push({
214 name,
215 indexUrl: groupVariants[0].mangaUrl!,
216 note,
217 data: entry.data,
218 variants: groupVariants
219 })
184 } 220 }
185 continue 221 continue
186 } 222 }
@@ -210,7 +246,8 @@ export function extRepoPlugin(md: MarkdownIt): void {
210 246
211 const token = state.push('html_block', '', 0) 247 const token = state.push('html_block', '', 0)
212 token.map = [startLine, nextLine] 248 token.map = [startLine, nextLine]
213 token.content = `<ExtensionRepos scheme="${scheme}"${fromAttr} :repos='${reposJson}' />\n` 249 token.content =
250 `<ExtensionRepos scheme="${scheme}"${fromAttr}${manualAttr} :repos='${reposJson}' />\n`
214 251
215 state.line = found ? nextLine + 1 : nextLine 252 state.line = found ? nextLine + 1 : nextLine
216 return true 253 return true
docs/.vitepress/theme/components/extrepo/ContentTypeFilter.vue deleted −179
@@ -1,179 +0,0 @@
1<script setup lang="ts">
2import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui'
3import { computed, onMounted, onUnmounted, ref } from 'vue'
4import { contentTypeLabel } from './helpers'
5import MenuHelp from '../settings/MenuHelp.vue'
6import MenuTitle from '../settings/MenuTitle.vue'
7
8const props = withDefaults(defineProps<{
9 // Excluded type values; empty means nothing is excluded, so everything is shown.
10 modelValue: Set<string>
11 availableTypes: string[]
12 title?: string
13 icon?: string
14 helpText?: string
15}>(), {
16 title: 'Content Type',
17 icon: 'i-lucide:tags',
18 helpText: 'Shows or hides specific content types. Unchecking a type hides matching entries from the list.'
19})
20
21const emit = defineEmits<{
22 'update:modelValue': [value: Set<string>]
23}>()
24
25const rootRef = ref<HTMLElement>()
26const open = ref(false)
27const menuTitleElementRef = ref<HTMLDivElement>()
28const isMenuHelpPoppedUp = ref(false)
29
30const selectedCount = computed(() => props.availableTypes.length - props.modelValue.size)
31const summaryLabel = computed(() => {
32 if (props.modelValue.size === 0) return 'All types'
33 return `${selectedCount.value} of ${props.availableTypes.length}`
34})
35
36function isChecked(type: string): boolean {
37 return !props.modelValue.has(type)
38}
39
40function toggle(type: string) {
41 const next = new Set(props.modelValue)
42 if (next.has(type)) next.delete(type)
43 else next.add(type)
44 emit('update:modelValue', next)
45}
46
47function onDocClick(e: MouseEvent) {
48 if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false
49}
50
51onMounted(() => document.addEventListener('click', onDocClick, true))
52onUnmounted(() => document.removeEventListener('click', onDocClick, true))
53</script>
54
55<template>
56 <div ref="rootRef" class="ext-ctype-select" :class="{ 'ext-ctype-select--open': open }">
57 <div ref="menuTitleElementRef" relative flex items-center mb-2>
58 <MenuTitle :title="title" :aria-label="title" flex="1" pr-4>
59 <template #icon>
60 <span :class="icon" mr-1 aria-hidden="true" />
61 </template>
62 </MenuTitle>
63 <MenuHelp
64 v-model:is-popped-up="isMenuHelpPoppedUp"
65 :menu-title-element-ref="menuTitleElementRef"
66 >
67 <h4 text-md mb-1 font-semibold>{{ title }}</h4>
68 <p text="sm" mb-2 max-w-100>
69 {{ helpText }}
70 </p>
71 </MenuHelp>
72 </div>
73 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
74 <button
75 type="button"
76 class="ext-ctype-trigger"
77 aria-haspopup="listbox"
78 :aria-expanded="open"
79 @click="open = !open"
80 >
81 <span class="ext-ctype-label">{{ summaryLabel }}</span>
82 <span class="ext-ctype-chevron i-lucide:chevron-down" :class="{ 'ext-ctype-chevron--open': open }" />
83 </button>
84
85 <NuVerticalTransition :duration="200">
86 <div v-show="open" class="ext-ctype-options" role="listbox">
87 <label v-for="type in availableTypes" :key="type" class="ext-ctype-option">
88 <input type="checkbox" :checked="isChecked(type)" @change="toggle(type)" />
89 <span class="ext-ctype-option-label">{{ contentTypeLabel(type) }}</span>
90 </label>
91 </div>
92 </NuVerticalTransition>
93 </NuInputHighlight>
94 </div>
95</template>
96
97<style scoped>
98.ext-ctype-select {
99 position: relative;
100}
101
102.ext-ctype-trigger {
103 display: flex;
104 align-items: center;
105 gap: 8px;
106 width: 100%;
107 min-height: 44px;
108 padding: 7px 10px;
109 border-radius: 8px;
110 border: 2px solid var(--vp-c-divider);
111 background: var(--wk-c-menu-bg);
112 color: var(--vp-c-text-1);
113 font-size: 13px;
114 cursor: pointer;
115 transition: border-color 0.15s, background-color 0.15s;
116}
117
118.ext-ctype-trigger:hover,
119.ext-ctype-select--open .ext-ctype-trigger {
120 border-color: var(--vp-c-brand-1);
121}
122
123.ext-ctype-label {
124 flex: 1;
125 text-align: left;
126}
127
128.ext-ctype-chevron {
129 flex-shrink: 0;
130 color: var(--vp-c-text-2);
131 transition: transform 0.2s ease;
132}
133
134.ext-ctype-chevron--open {
135 transform: rotate(180deg);
136}
137
138.ext-ctype-options {
139 margin-top: 6px;
140 max-height: 240px;
141 overflow-y: auto;
142 overscroll-behavior: contain;
143 display: flex;
144 flex-direction: column;
145 gap: 2px;
146 padding: 4px;
147 border-radius: 8px;
148 border: 1px solid var(--vp-c-divider);
149 background: var(--vp-c-bg-elv);
150 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2));
151}
152
153.ext-ctype-option {
154 display: flex;
155 align-items: center;
156 gap: 8px;
157 padding: 5px 8px;
158 border-radius: 8px;
159 cursor: pointer;
160 color: var(--vp-c-text-1);
161 font-size: 13px;
162 width: 100%;
163 transition: background-color 0.15s;
164}
165
166.ext-ctype-option:hover {
167 background-color: var(--vp-c-bg-soft);
168}
169
170.ext-ctype-option input {
171 flex-shrink: 0;
172 accent-color: var(--vp-c-brand-1);
173}
174
175.ext-ctype-option-label {
176 flex: 1;
177 min-width: 0;
178}
179</style>
docs/.vitepress/theme/components/extrepo/ExtensionRepos.vue +170 −89
@@ -1,54 +1,124 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { computed, ref } from 'vue' 2import { refDebounced } from '@vueuse/core'
3import { data } from '../../../../ext/extensionRepos.data' 3import { computed, onUnmounted, ref } from 'vue'
4import { escapeHtml, langLabel, stripHtml } from './helpers' 4import { SEARCH_DEBOUNCE_MS, STATUS_TICK_MS } from './constants'
5import { escapeHtml, stripHtml } from './helpers'
5import { mangayomiCopyValue } from './install' 6import { mangayomiCopyValue } from './install'
6import RepoRow from './RepoRow.vue' 7import RepoRow from './RepoRow.vue'
7import SettingsMenu from './SettingsMenu.vue' 8import SettingsMenu from './SettingsMenu.vue'
8import SiteGrid from './SiteGrid.vue' 9import SiteGrid from './SiteGrid.vue'
9import type { MatchedSite, RatingFilter, Repo } from './types' 10import type { MatchedSite, RatingFilter, Repo } from './types'
11import { indexSites, useRepoFilter } from './useRepoFilter'
12import { provideRepoStore } from './useRepoStore'
10import { provideTooltip } from './useTooltip' 13import { provideTooltip } from './useTooltip'
11 14
12const { tooltip } = provideTooltip() 15const { tooltip } = provideTooltip()
13 16
14const repoData = data.sites
15const soraAuthors = data.soraAuthors
16const echoAuthors = data.echoAuthors
17const repoLists = data.repoLists ?? {}
18
19const props = defineProps<{ 17const props = defineProps<{
20 repos: Repo[] 18 repos: Repo[]
21 scheme: string 19 scheme: string
22 from?: string 20 from?: string
21 manual?: boolean
23}>() 22}>()
24 23
24const {
25 store,
26 loading,
27 refreshing,
28 refreshFailed,
29 loadFailed,
30 updatedAt,
31 loadMs,
32 refresh,
33 retry
34} = provideRepoStore(props.scheme)
35
36const ticked = ref(false)
37let tickTimer: ReturnType<typeof setTimeout> | undefined
38
39onUnmounted(() => {
40 if (tickTimer) clearTimeout(tickTimer)
41})
42
43async function onStatusClick() {
44 if (loading.value || refreshing.value) return
45 if (loadFailed.value) {
46 await retry()
47 return
48 }
49 ticked.value = false
50 if (tickTimer) clearTimeout(tickTimer)
51 await refresh()
52 if (!refreshFailed.value) {
53 ticked.value = true
54 tickTimer = setTimeout(() => {
55 ticked.value = false
56 }, STATUS_TICK_MS)
57 }
58}
59
60const busy = computed(() => loading.value || refreshing.value)
61const failed = computed(() => loadFailed.value || refreshFailed.value)
62
63const statusIcon = computed(() => {
64 if (busy.value) return 'i-lucide:loader-circle'
65 if (failed.value) return 'i-lucide:x'
66 if (ticked.value) return 'i-lucide:check'
67 return 'i-lucide:refresh-cw'
68})
69
70const statusTitle = computed(() => {
71 const ms = loadMs.value !== null ? ` (${loadMs.value}ms)` : ''
72 if (loading.value) return `Loading sites…${ms}`
73 if (refreshing.value) return 'Refreshing…'
74 if (failed.value) return `Loading failed${ms} — click to retry`
75 if (ticked.value) return 'Database refreshed'
76 if (updatedAt.value) {
77 return `Database refreshed at ${new Date(updatedAt.value).toLocaleTimeString()}`
78 }
79 return `Refresh data${ms}`
80})
81
82const repoData = computed(() => store.value?.sites ?? {})
83const echoAuthors = computed(() => store.value?.echoAuthors ?? {})
84const repoLists = computed(() => store.value?.repoLists ?? {})
85
25const baseRepos = computed<Repo[]>(() => { 86const baseRepos = computed<Repo[]>(() => {
26 const list = props.from ? repoLists[props.from] ?? [] : [] 87 const list = props.from ? repoLists.value[props.from] ?? [] : []
27 const auto: Repo[] = list.map(entry => ({ 88 const auto: Repo[] = list.map(entry => ({
28 name: entry.repoUrl 89 name: entry.repoUrl
29 ? `<a href="${entry.repoUrl}" target="_blank" rel="noopener noreferrer">${escapeHtml(entry.label)}</a>` 90 ? `<a href="${entry.repoUrl}" target="_blank" rel="noopener noreferrer">${
91 escapeHtml(entry.label)
92 }</a>`
30 : escapeHtml(entry.label), 93 : escapeHtml(entry.label),
31 indexUrl: entry.indexUrl, 94 indexUrl: entry.indexUrl,
32 repoName: entry.label, 95 repoName: entry.label,
33 repoUrl: entry.repoUrl 96 repoUrl: entry.repoUrl
34 })) 97 }))
35 const manualByUrl = new Map(props.repos.map(repo => [repo.indexUrl, repo])) 98 const manualByUrl = new Map(props.repos.map(repo => [repo.indexUrl, repo]))
36 const merged = [...auto.filter(repo => !manualByUrl.has(repo.indexUrl)), ...props.repos] 99 const merged = [
37 merged.sort((a, b) => stripHtml(a.name).localeCompare(stripHtml(b.name))) 100 ...auto.filter(repo => !manualByUrl.has(repo.indexUrl)),
101 ...props.repos
102 ]
103 if (!props.manual) {
104 merged.sort((a, b) => stripHtml(a.name).localeCompare(stripHtml(b.name)))
105 }
38 return merged 106 return merged
39}) 107})
40 108
41const resolvedRepos = computed<Repo[]>(() => { 109const resolvedRepos = computed<Repo[]>(() => {
42 const result: Repo[] = [] 110 const result: Repo[] = []
43 for (const repo of baseRepos.value) { 111 for (const repo of baseRepos.value) {
44 const authors = soraAuthors[repo.indexUrl] ?? echoAuthors[repo.indexUrl] 112 const authors = echoAuthors.value[repo.indexUrl]
45 if (!authors?.length) { 113 if (!authors?.length) {
46 result.push(repo) 114 result.push(repo)
47 continue 115 continue
48 } 116 }
49 for (const author of authors) { 117 for (const author of authors) {
50 const name = author.repoUrl 118 const name = author.repoUrl
51 ? `<a href="${author.repoUrl}" target="_blank" rel="noopener noreferrer">${escapeHtml(author.label)}</a>` 119 ? `<a href="${author.repoUrl}" target="_blank" rel="noopener noreferrer">${
120 escapeHtml(author.label)
121 }</a>`
52 : escapeHtml(author.label) 122 : escapeHtml(author.label)
53 result.push({ name, indexUrl: author.indexUrl, repoName: author.label }) 123 result.push({ name, indexUrl: author.indexUrl, repoName: author.label })
54 } 124 }
@@ -57,24 +127,22 @@ const resolvedRepos = computed<Repo[]>(() => {
57}) 127})
58 128
59const query = ref('') 129const query = ref('')
130const debouncedQuery = refDebounced(query, SEARCH_DEBOUNCE_MS)
60const langFilter = ref('') 131const langFilter = ref('')
61const ratingFilter = ref<RatingFilter>('all') 132const ratingFilter = ref<RatingFilter>('all')
62const contentTypeFilter = ref('') 133const contentTypeFilter = ref('')
63const excludedStreamTypes = ref<Set<string>>(new Set())
64const excludedQualities = ref<Set<string>>(new Set())
65const showBroken = ref(false) 134const showBroken = ref(false)
66 135
67const allSites = computed<MatchedSite[]>(() => { 136const allSites = computed(() => {
68 const sites: MatchedSite[] = [] 137 const sites: MatchedSite[] = []
69 for (const repo of resolvedRepos.value) { 138 for (const repo of resolvedRepos.value) {
70 if (repo.variants?.length) { 139 if (repo.variants?.length) {
71 // search fix for variations of setup. (mangayomi and kotatsu)
72 const sameRepoName = repo.repoName ? stripHtml(repo.name) : undefined 140 const sameRepoName = repo.repoName ? stripHtml(repo.name) : undefined
73 for (const variant of repo.variants) { 141 for (const variant of repo.variants) {
74 const url = mangayomiCopyValue(variant) 142 const url = mangayomiCopyValue(variant)
75 if (!url) continue 143 if (!url) continue
76 const repoName = sameRepoName ?? variant.label 144 const repoName = sameRepoName ?? variant.label
77 for (const site of repoData[url]?.sites ?? []) { 145 for (const site of repoData.value[url]?.sites ?? []) {
78 sites.push({ ...site, repoName }) 146 sites.push({ ...site, repoName })
79 } 147 }
80 } 148 }
@@ -82,62 +150,19 @@ const allSites = computed<MatchedSite[]>(() => {
82 } 150 }
83 const repoName = stripHtml(repo.name) 151 const repoName = stripHtml(repo.name)
84 const dataUrl = repo.data ?? repo.indexUrl 152 const dataUrl = repo.data ?? repo.indexUrl
85 for (const site of repoData[dataUrl]?.sites ?? []) { 153 for (const site of repoData.value[dataUrl]?.sites ?? []) {
86 sites.push({ ...site, repoName }) 154 sites.push({ ...site, repoName })
87 } 155 }
88 } 156 }
89 return sites 157 return indexSites(sites)
90})
91
92const availableContentTypes = computed(() => {
93 const types = new Set<string>()
94 for (const site of allSites.value) if (site.contentType) types.add(site.contentType)
95 return [...types].sort()
96}) 158})
97const hasContentTypes = computed(() => availableContentTypes.value.length > 0)
98 159
99const availableStreamTypes = computed(() => { 160const { facets, isFiltering, filteredSites } = useRepoFilter(allSites, {
100 const types = new Set<string>() 161 query: debouncedQuery,
101 for (const site of allSites.value) if (site.streamType) types.add(site.streamType) 162 langFilter,
102 return [...types].sort() 163 ratingFilter,
103}) 164 contentTypeFilter,
104const hasStreamTypes = computed(() => availableStreamTypes.value.length > 0) 165 showBroken
105
106const availableQualities = computed(() => {
107 const types = new Set<string>()
108 for (const site of allSites.value) if (site.quality) types.add(site.quality)
109 return [...types].sort()
110})
111const hasQualities = computed(() => availableQualities.value.length > 0)
112
113const hasRatings = computed(() => allSites.value.some(site => site.rating !== 'safe'))
114const hasSuggestive = computed(() => allSites.value.some(site => site.rating === 'suggestive'))
115const hasMultiLanguage = computed(() => allSites.value.some(site => site.lang.toLowerCase() === 'all'))
116const hasBroken = computed(() => allSites.value.some(site => site.isBroken))
117
118const availableLangs = computed(() => {
119 const codes = new Set(allSites.value.map(site => site.lang))
120 codes.delete('all')
121 return [...codes].sort((a, b) => langLabel(a).localeCompare(langLabel(b)))
122})
123
124const isFiltering = computed(() => {
125 return query.value.trim() !== '' || langFilter.value !== '' || ratingFilter.value !== 'all'
126 || contentTypeFilter.value !== '' || excludedStreamTypes.value.size > 0 || excludedQualities.value.size > 0
127})
128
129const filteredSites = computed(() => {
130 const q = query.value.trim().toLowerCase()
131 return allSites.value.filter(site => {
132 if (site.isBroken && !showBroken.value) return false
133 if (q && !site.name.toLowerCase().includes(q) && !site.url.toLowerCase().includes(q)) return false
134 if (langFilter.value && site.lang !== langFilter.value) return false
135 if (ratingFilter.value !== 'all' && site.rating !== ratingFilter.value) return false
136 if (contentTypeFilter.value && site.contentType !== contentTypeFilter.value) return false
137 if (site.streamType && excludedStreamTypes.value.has(site.streamType)) return false
138 if (site.quality && excludedQualities.value.has(site.quality)) return false
139 return true
140 })
141}) 166})
142</script> 167</script>
143 168
@@ -148,24 +173,33 @@ const filteredSites = computed(() => {
148 <span class="i-lucide:search" /> 173 <span class="i-lucide:search" />
149 <input v-model="query" type="text" placeholder="Search all sites…" /> 174 <input v-model="query" type="text" placeholder="Search all sites…" />
150 </div> 175 </div>
176 <button
177 type="button"
178 class="ext-status-btn"
179 :class="{
180 spinning: busy,
181 'is-failed': !busy && failed,
182 'is-ok': !busy && !failed && ticked
183 }"
184 :disabled="busy"
185 :title="statusTitle"
186 aria-label="Reload site data"
187 @click="onStatusClick"
188 >
189 <span :class="statusIcon" />
190 </button>
151 <SettingsMenu 191 <SettingsMenu
152 v-model:lang-filter="langFilter" 192 v-model:lang-filter="langFilter"
153 v-model:rating-filter="ratingFilter" 193 v-model:rating-filter="ratingFilter"
154 v-model:content-type-filter="contentTypeFilter" 194 v-model:content-type-filter="contentTypeFilter"
155 v-model:stream-type-filter="excludedStreamTypes"
156 v-model:quality-filter="excludedQualities"
157 v-model:show-broken="showBroken" 195 v-model:show-broken="showBroken"
158 :available-langs="availableLangs" 196 :available-langs="facets.availableLangs"
159 :has-multi-language="hasMultiLanguage" 197 :has-multi-language="facets.hasMultiLanguage"
160 :has-ratings="hasRatings" 198 :has-ratings="facets.hasRatings"
161 :has-suggestive="hasSuggestive" 199 :has-suggestive="facets.hasSuggestive"
162 :available-content-types="availableContentTypes" 200 :available-content-types="facets.availableContentTypes"
163 :has-content-types="hasContentTypes" 201 :has-content-types="facets.availableContentTypes.length > 0"
164 :available-stream-types="availableStreamTypes" 202 :has-broken="facets.hasBroken"
165 :has-stream-types="hasStreamTypes"
166 :available-qualities="availableQualities"
167 :has-qualities="hasQualities"
168 :has-broken="hasBroken"
169 /> 203 />
170 </div> 204 </div>
171 205
@@ -178,7 +212,13 @@ const filteredSites = computed(() => {
178 /> 212 />
179 213
180 <div v-else> 214 <div v-else>
181 <RepoRow v-for="repo in resolvedRepos" :key="repo.indexUrl" :repo="repo" :scheme="scheme" :show-broken="showBroken" /> 215 <RepoRow
216 v-for="repo in resolvedRepos"
217 :key="repo.indexUrl"
218 :repo="repo"
219 :scheme="scheme"
220 :show-broken="showBroken"
221 />
182 </div> 222 </div>
183 </div> 223 </div>
184 224
@@ -187,7 +227,9 @@ const filteredSites = computed(() => {
187 v-if="tooltip" 227 v-if="tooltip"
188 class="ext-fixed-tooltip" 228 class="ext-fixed-tooltip"
189 :style="{ left: tooltip.x + 'px', top: tooltip.y + 'px' }" 229 :style="{ left: tooltip.x + 'px', top: tooltip.y + 'px' }"
190 >{{ tooltip.text }}</div> 230 >
231 {{ tooltip.text }}
232 </div>
191 </Teleport> 233 </Teleport>
192</template> 234</template>
193 235
@@ -198,7 +240,6 @@ const filteredSites = computed(() => {
198 border-radius: var(--radius-xl, 12px); 240 border-radius: var(--radius-xl, 12px);
199 overflow: hidden; 241 overflow: hidden;
200} 242}
201
202.ext-toolbar { 243.ext-toolbar {
203 display: flex; 244 display: flex;
204 flex-wrap: wrap; 245 flex-wrap: wrap;
@@ -208,7 +249,6 @@ const filteredSites = computed(() => {
208 background-color: var(--vp-c-bg-soft); 249 background-color: var(--vp-c-bg-soft);
209 border-bottom: 1px solid var(--vp-c-divider); 250 border-bottom: 1px solid var(--vp-c-divider);
210} 251}
211
212.ext-search { 252.ext-search {
213 display: flex; 253 display: flex;
214 align-items: center; 254 align-items: center;
@@ -220,7 +260,6 @@ const filteredSites = computed(() => {
220 background-color: var(--vp-c-bg); 260 background-color: var(--vp-c-bg);
221 color: var(--vp-c-text-2); 261 color: var(--vp-c-text-2);
222} 262}
223
224.ext-search input { 263.ext-search input {
225 flex: 1; 264 flex: 1;
226 min-width: 0; 265 min-width: 0;
@@ -230,7 +269,49 @@ const filteredSites = computed(() => {
230 color: var(--vp-c-text-1); 269 color: var(--vp-c-text-1);
231 font-size: 13px; 270 font-size: 13px;
232} 271}
233 272.ext-status-btn {
273 display: flex;
274 align-items: center;
275 justify-content: center;
276 width: 30px;
277 height: 30px;
278 padding: 0;
279 border: none;
280 border-radius: 0;
281 background: transparent;
282 color: var(--vp-c-text-1);
283 opacity: 0.55;
284 cursor: pointer;
285 transition: opacity 0.25s;
286}
287.ext-status-btn:hover:not(:disabled) {
288 opacity: 1;
289}
290.ext-status-btn:disabled {
291 cursor: default;
292}
293.ext-status-btn span {
294 font-size: 15px;
295}
296.ext-status-btn.spinning span {
297 animation: ext-spin 1s linear infinite;
298}
299.ext-status-btn.is-failed {
300 color: var(--vp-c-red-2, #e5484d);
301 opacity: 1;
302}
303.ext-status-btn.is-ok {
304 color: var(--vp-c-green-1, #3dd68c);
305 opacity: 1;
306}
307@keyframes ext-spin {
308 to {
309 transform: rotate(360deg);
310 }
311}
312html.effects-disabled .ext-status-btn.spinning span {
313 animation: none;
314}
234.ext-fixed-tooltip { 315.ext-fixed-tooltip {
235 position: fixed; 316 position: fixed;
236 z-index: 9999; 317 z-index: 9999;
docs/.vitepress/theme/components/extrepo/TypeSelect.vue → docs/.vitepress/theme/components/extrepo/FilterSelect.vue renamed +79 −71
@@ -1,90 +1,105 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui' 2import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui'
3import { onMounted, onUnmounted, ref } from 'vue' 3import { computed, ref } from 'vue'
4import { contentTypeLabel } from './helpers'
5import MenuHelp from '../settings/MenuHelp.vue' 4import MenuHelp from '../settings/MenuHelp.vue'
6import MenuTitle from '../settings/MenuTitle.vue' 5import MenuTitle from '../settings/MenuTitle.vue'
6import { useDropdown } from './useDropdown'
7 7
8defineProps<{ 8export interface FilterOption {
9 modelValue: string 9 value: string
10 availableTypes: string[] 10 label: string
11}>() 11 flag?: string
12}
13
14const props = withDefaults(
15 defineProps<{
16 title: string
17 icon: string
18 helpText: string
19 options: FilterOption[]
20 modelValue: string
21 triggerLabel?: string
22 }>(),
23 {
24 triggerLabel: undefined
25 }
26)
12 27
13const emit = defineEmits<{ 28const emit = defineEmits<{
14 'update:modelValue': [value: string] 29 'update:modelValue': [value: string]
15}>() 30}>()
16 31
17const rootRef = ref<HTMLElement>() 32const { rootRef, open, toggle } = useDropdown()
18const open = ref(false)
19const menuTitleElementRef = ref<HTMLDivElement>() 33const menuTitleElementRef = ref<HTMLDivElement>()
20const isMenuHelpPoppedUp = ref(false) 34const isMenuHelpPoppedUp = ref(false)
21 35
22function select(type: string) { 36const currentLabel = computed(() => {
23 emit('update:modelValue', type) 37 if (props.triggerLabel) return props.triggerLabel
24 open.value = false 38 return props.options.find(o => o.value === props.modelValue)?.label ?? 'All'
25} 39})
26 40
27function onDocClick(e: MouseEvent) { 41function select(value: string) {
28 if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false 42 emit('update:modelValue', value)
43 open.value = false
29} 44}
30
31onMounted(() => document.addEventListener('click', onDocClick, true))
32onUnmounted(() => document.removeEventListener('click', onDocClick, true))
33</script> 45</script>
34 46
35<template> 47<template>
36 <div ref="rootRef" class="ext-type-select" :class="{ 'ext-type-select--open': open }"> 48 <div ref="rootRef" class="ext-fselect" :class="{ 'ext-fselect--open': open }">
37 <div ref="menuTitleElementRef" relative flex items-center mb-2> 49 <div ref="menuTitleElementRef" relative flex items-center mb-2>
38 <MenuTitle title="Type" aria-label="Type" flex="1" pr-4> 50 <MenuTitle :title="title" :aria-label="title" flex="1" pr-4>
39 <template #icon> 51 <template #icon>
40 <span i-lucide:tags mr-1 aria-hidden="true" /> 52 <span :class="icon" mr-1 aria-hidden="true" />
41 </template> 53 </template>
42 </MenuTitle> 54 </MenuTitle>
43 <MenuHelp 55 <MenuHelp
44 v-model:is-popped-up="isMenuHelpPoppedUp" 56 v-model:is-popped-up="isMenuHelpPoppedUp"
45 :menu-title-element-ref="menuTitleElementRef" 57 :menu-title-element-ref="menuTitleElementRef"
46 > 58 >
47 <h4 text-md mb-1 font-semibold>Type</h4> 59 <h4 text-md mb-1 font-semibold>{{ title }}</h4>
48 <p text="sm" mb-2 max-w-100> 60 <p text="sm" mb-2 max-w-100>
49 Filters extensions by type. 61 {{ helpText }}
50 </p> 62 </p>
63 <slot name="help-extra" />
51 </MenuHelp> 64 </MenuHelp>
52 </div> 65 </div>
53 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md"> 66 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
54 <button 67 <button
55 type="button" 68 type="button"
56 class="ext-type-trigger" 69 class="ext-fselect-trigger"
57 aria-haspopup="listbox" 70 aria-haspopup="listbox"
58 :aria-expanded="open" 71 :aria-expanded="open"
59 @click="open = !open" 72 @click="toggle"
60 > 73 >
61 <span class="ext-type-label">{{ modelValue ? contentTypeLabel(modelValue) : 'All types' }}</span> 74 <span class="ext-fselect-label">{{ currentLabel }}</span>
62 <span class="ext-type-chevron i-lucide:chevron-down" :class="{ 'ext-type-chevron--open': open }" /> 75 <span
76 class="ext-fselect-chevron i-lucide:chevron-down"
77 :class="{ 'ext-fselect-chevron--open': open }"
78 />
63 </button> 79 </button>
64 80
65 <NuVerticalTransition :duration="200"> 81 <NuVerticalTransition :duration="200">
66 <div v-show="open" class="ext-type-options" role="listbox"> 82 <div v-show="open" class="ext-fselect-options" role="listbox">
67 <button
68 type="button"
69 role="option"
70 class="ext-type-option"
71 :class="{ 'ext-type-option--selected': modelValue === '' }"
72 :aria-selected="modelValue === ''"
73 @click="select('')"
74 >
75 <span class="ext-type-option-label">All types</span>
76 </button>
77 <button 83 <button
78 v-for="type in availableTypes" 84 v-for="option in options"
79 :key="type" 85 :key="option.value"
80 type="button" 86 type="button"
81 role="option" 87 role="option"
82 class="ext-type-option" 88 class="ext-fselect-option"
83 :class="{ 'ext-type-option--selected': modelValue === type }" 89 :class="{
84 :aria-selected="modelValue === type" 90 'ext-fselect-option--selected':
85 @click="select(type)" 91 modelValue === option.value
92 }"
93 :aria-selected="modelValue === option.value"
94 @click="select(option.value)"
86 > 95 >
87 <span class="ext-type-option-label">{{ contentTypeLabel(type) }}</span> 96 <span class="ext-fselect-option-label">{{ option.label }}</span>
97 <span
98 v-if="option.flag"
99 class="ext-fselect-option-flag"
100 :class="option.flag"
101 aria-hidden="true"
102 />
88 </button> 103 </button>
89 </div> 104 </div>
90 </NuVerticalTransition> 105 </NuVerticalTransition>
@@ -93,11 +108,10 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true))
93</template> 108</template>
94 109
95<style scoped> 110<style scoped>
96.ext-type-select { 111.ext-fselect {
97 position: relative; 112 position: relative;
98} 113}
99 114.ext-fselect-trigger {
100.ext-type-trigger {
101 display: flex; 115 display: flex;
102 align-items: center; 116 align-items: center;
103 gap: 8px; 117 gap: 8px;
@@ -112,28 +126,23 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true))
112 cursor: pointer; 126 cursor: pointer;
113 transition: border-color 0.15s, background-color 0.15s; 127 transition: border-color 0.15s, background-color 0.15s;
114} 128}
115 129.ext-fselect-trigger:hover,
116.ext-type-trigger:hover, 130.ext-fselect--open .ext-fselect-trigger {
117.ext-type-select--open .ext-type-trigger {
118 border-color: var(--vp-c-brand-1); 131 border-color: var(--vp-c-brand-1);
119} 132}
120 133.ext-fselect-label {
121.ext-type-label {
122 flex: 1; 134 flex: 1;
123 text-align: left; 135 text-align: left;
124} 136}
125 137.ext-fselect-chevron {
126.ext-type-chevron {
127 flex-shrink: 0; 138 flex-shrink: 0;
128 color: var(--vp-c-text-2); 139 color: var(--vp-c-text-2);
129 transition: transform 0.2s ease; 140 transition: transform 0.2s ease;
130} 141}
131 142.ext-fselect-chevron--open {
132.ext-type-chevron--open {
133 transform: rotate(180deg); 143 transform: rotate(180deg);
134} 144}
135 145.ext-fselect-options {
136.ext-type-options {
137 margin-top: 6px; 146 margin-top: 6px;
138 max-height: 240px; 147 max-height: 240px;
139 overflow-y: auto; 148 overflow-y: auto;
@@ -147,8 +156,7 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true))
147 background: var(--vp-c-bg-elv); 156 background: var(--vp-c-bg-elv);
148 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2)); 157 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2));
149} 158}
150 159.ext-fselect-option {
151.ext-type-option {
152 display: flex; 160 display: flex;
153 align-items: center; 161 align-items: center;
154 gap: 8px; 162 gap: 8px;
@@ -163,22 +171,22 @@ onUnmounted(() => document.removeEventListener('click', onDocClick, true))
163 width: 100%; 171 width: 100%;
164 transition: background-color 0.15s; 172 transition: background-color 0.15s;
165} 173}
166 174.ext-fselect-option:hover {
167.ext-type-option-label {
168 flex: 1;
169 min-width: 0;
170}
171
172.ext-type-option:hover {
173 background-color: var(--vp-c-bg-soft); 175 background-color: var(--vp-c-bg-soft);
174} 176}
175 177.ext-fselect-option--selected {
176.ext-type-option--selected {
177 background-color: var(--vp-c-brand-soft); 178 background-color: var(--vp-c-brand-soft);
178 font-weight: 600; 179 font-weight: 600;
179} 180}
180 181.ext-fselect-option--selected:hover {
181.ext-type-option--selected:hover {
182 background-color: var(--vp-c-brand-soft); 182 background-color: var(--vp-c-brand-soft);
183} 183}
184.ext-fselect-option-label {
185 flex: 1;
186 min-width: 0;
187}
188.ext-fselect-option-flag {
189 flex-shrink: 0;
190 font-size: 14px;
191}
184</style> 192</style>
docs/.vitepress/theme/components/extrepo/LangSelect.vue deleted −204
@@ -1,204 +0,0 @@
1<script setup lang="ts">
2import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui'
3import { onMounted, onUnmounted, ref } from 'vue'
4import { langFlagClass, langLabel } from './helpers'
5import MenuHelp from '../settings/MenuHelp.vue'
6import MenuTitle from '../settings/MenuTitle.vue'
7
8defineProps<{
9 modelValue: string
10 availableLangs: string[]
11 hasMultiLanguage: boolean
12}>()
13
14const emit = defineEmits<{
15 'update:modelValue': [value: string]
16}>()
17
18const rootRef = ref<HTMLElement>()
19const open = ref(false)
20const menuTitleElementRef = ref<HTMLDivElement>()
21const isMenuHelpPoppedUp = ref(false)
22
23function select(lang: string) {
24 emit('update:modelValue', lang)
25 open.value = false
26}
27
28function onDocClick(e: MouseEvent) {
29 if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false
30}
31
32onMounted(() => document.addEventListener('click', onDocClick, true))
33onUnmounted(() => document.removeEventListener('click', onDocClick, true))
34</script>
35
36<template>
37 <div ref="rootRef" class="ext-lang-select" :class="{ 'ext-lang-select--open': open }">
38 <div ref="menuTitleElementRef" relative flex items-center mb-2>
39 <MenuTitle title="Language" aria-label="Language" flex="1" pr-4>
40 <template #icon>
41 <span i-lucide:languages mr-1 aria-hidden="true" />
42 </template>
43 </MenuTitle>
44 <MenuHelp
45 v-model:is-popped-up="isMenuHelpPoppedUp"
46 :menu-title-element-ref="menuTitleElementRef"
47 >
48 <h4 text-md mb-1 font-semibold>Language</h4>
49 <p text="sm" mb-2 max-w-100>
50 Filters extensions by translated language (not original language).
51 </p>
52 </MenuHelp>
53 </div>
54 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
55 <button
56 type="button"
57 class="ext-lang-trigger"
58 aria-haspopup="listbox"
59 :aria-expanded="open"
60 @click="open = !open"
61 >
62 <span class="ext-lang-label">{{ modelValue ? langLabel(modelValue) : 'All languages' }}</span>
63 <span class="ext-lang-chevron i-lucide:chevron-down" :class="{ 'ext-lang-chevron--open': open }" />
64 </button>
65
66 <NuVerticalTransition :duration="200">
67 <div v-show="open" class="ext-lang-options" role="listbox">
68 <button
69 type="button"
70 role="option"
71 class="ext-lang-option"
72 :class="{ 'ext-lang-option--selected': modelValue === '' }"
73 :aria-selected="modelValue === ''"
74 @click="select('')"
75 >
76 <span class="ext-lang-option-label">All languages</span>
77 <span class="ext-lang-option-flag" :class="langFlagClass('')" aria-hidden="true" />
78 </button>
79 <button
80 v-if="hasMultiLanguage"
81 type="button"
82 role="option"
83 class="ext-lang-option"
84 :class="{ 'ext-lang-option--selected': modelValue === 'all' }"
85 :aria-selected="modelValue === 'all'"
86 @click="select('all')"
87 >
88 <span class="ext-lang-option-label">Multi-language</span>
89 <span class="ext-lang-option-flag" :class="langFlagClass('all')" aria-hidden="true" />
90 </button>
91 <button
92 v-for="lang in availableLangs"
93 :key="lang"
94 type="button"
95 role="option"
96 class="ext-lang-option"
97 :class="{ 'ext-lang-option--selected': modelValue === lang }"
98 :aria-selected="modelValue === lang"
99 @click="select(lang)"
100 >
101 <span class="ext-lang-option-label">{{ langLabel(lang) }}</span>
102 <span class="ext-lang-option-flag" :class="langFlagClass(lang)" aria-hidden="true" />
103 </button>
104 </div>
105 </NuVerticalTransition>
106 </NuInputHighlight>
107 </div>
108</template>
109
110<style scoped>
111.ext-lang-select {
112 position: relative;
113}
114
115.ext-lang-trigger {
116 display: flex;
117 align-items: center;
118 gap: 8px;
119 width: 100%;
120 min-height: 44px;
121 padding: 7px 10px;
122 border-radius: 8px;
123 border: 2px solid var(--vp-c-divider);
124 background: var(--wk-c-menu-bg);
125 color: var(--vp-c-text-1);
126 font-size: 13px;
127 cursor: pointer;
128 transition: border-color 0.15s, background-color 0.15s;
129}
130
131.ext-lang-trigger:hover,
132.ext-lang-select--open .ext-lang-trigger {
133 border-color: var(--vp-c-brand-1);
134}
135
136.ext-lang-label {
137 flex: 1;
138 text-align: left;
139}
140
141.ext-lang-chevron {
142 flex-shrink: 0;
143 color: var(--vp-c-text-2);
144 transition: transform 0.2s ease;
145}
146
147.ext-lang-chevron--open {
148 transform: rotate(180deg);
149}
150
151.ext-lang-options {
152 margin-top: 6px;
153 max-height: 240px;
154 overflow-y: auto;
155 overscroll-behavior: contain;
156 display: flex;
157 flex-direction: column;
158 gap: 2px;
159 padding: 4px;
160 border-radius: 8px;
161 border: 1px solid var(--vp-c-divider);
162 background: var(--vp-c-bg-elv);
163 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2));
164}
165
166.ext-lang-option {
167 display: flex;
168 align-items: center;
169 gap: 8px;
170 padding: 5px 8px;
171 border-radius: 8px;
172 border: none;
173 background: transparent;
174 cursor: pointer;
175 color: var(--vp-c-text-1);
176 font-size: 13px;
177 text-align: left;
178 width: 100%;
179 transition: background-color 0.15s;
180}
181
182.ext-lang-option-label {
183 flex: 1;
184 min-width: 0;
185}
186
187.ext-lang-option-flag {
188 flex-shrink: 0;
189 font-size: 14px;
190}
191
192.ext-lang-option:hover {
193 background-color: var(--vp-c-bg-soft);
194}
195
196.ext-lang-option--selected {
197 background-color: var(--vp-c-brand-soft);
198 font-weight: 600;
199}
200
201.ext-lang-option--selected:hover {
202 background-color: var(--vp-c-brand-soft);
203}
204</style>
docs/.vitepress/theme/components/extrepo/LazyIcon.vue +68 −20
@@ -1,5 +1,6 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { onBeforeUnmount, onMounted, ref } from 'vue' 2import { onBeforeUnmount, onMounted, ref } from 'vue'
3import { iconResultCache, observeIcon } from './iconObserver'
3import { scheduleIconLoad } from './iconQueue' 4import { scheduleIconLoad } from './iconQueue'
4 5
5const props = defineProps<{ 6const props = defineProps<{
@@ -10,40 +11,87 @@ const props = defineProps<{
10const rootRef = ref<HTMLElement>() 11const rootRef = ref<HTMLElement>()
11const loaded = ref(false) 12const loaded = ref(false)
12const failed = ref(false) 13const failed = ref(false)
13let observer: IntersectionObserver | undefined 14let unobserve: (() => void) | undefined
15let cancelLoad: (() => void) | undefined
14 16
15onMounted(() => { 17function startLoad() {
16 const el = rootRef.value 18 if (!props.src) return
17 if (!el || !props.src) return 19 const cached = iconResultCache.get(props.src)
18 // Preload a bit before the card is actually visible so it's ready by the time it scrolls in. 20 if (cached !== undefined) {
19 observer = new IntersectionObserver((entries) => { 21 if (cached) loaded.value = true
20 if (!entries.some(entry => entry.isIntersecting)) return 22 else failed.value = true
21 observer?.disconnect() 23 return
22 scheduleIconLoad(() => new Promise<void>((resolve) => { 24 }
25 cancelLoad = scheduleIconLoad(() =>
26 new Promise<void>((resolve) => {
23 const img = new Image() 27 const img = new Image()
24 img.onload = () => { 28 img.onload = () => {
25 loaded.value = true 29 loaded.value = true
30 iconResultCache.set(props.src!, true)
26 resolve() 31 resolve()
27 } 32 }
28 img.onerror = () => { 33 img.onerror = () => {
29 failed.value = true 34 failed.value = true
35 iconResultCache.set(props.src!, false)
30 resolve() 36 resolve()
31 } 37 }
32 img.src = props.src! 38 img.src = props.src!
33 })) 39 })
34 }, { rootMargin: '200px' }) 40 )
35 observer.observe(el) 41}
42
43onMounted(() => {
44 const el = rootRef.value
45 if (!el) return
46 if (!props.src) return
47 unobserve = observeIcon(el, () => {
48 startLoad()
49 })
36}) 50})
37 51
38onBeforeUnmount(() => observer?.disconnect()) 52onBeforeUnmount(() => {
53 unobserve?.()
54 cancelLoad?.()
55})
39</script> 56</script>
40 57
41<template> 58<template>
42 <img v-if="loaded" ref="rootRef" :src="src" :alt="alt" /> 59 <span ref="rootRef" class="ext-site-icon-slot">
43 <span 60 <img v-if="loaded" :src="src" :alt="alt" loading="lazy" decoding="async" />
44 v-else 61 <span
45 ref="rootRef" 62 v-else
46 class="ext-site-icon-fallback" 63 class="ext-site-icon-fallback"
47 :class="{ 'i-lucide:globe': !src || failed, 'ext-site-icon-loading': src && !failed }" 64 :class="{
48 /> 65 'i-lucide:globe': !src || failed,
66 'ext-site-icon-loading': src && !failed
67 }"
68 />
69 </span>
49</template> 70</template>
71
72<style scoped>
73.ext-site-icon-slot {
74 width: 18px;
75 height: 18px;
76 flex-shrink: 0;
77 display: inline-flex;
78}
79.ext-site-icon-slot img {
80 width: 18px;
81 height: 18px;
82 border-radius: 4px;
83 object-fit: contain;
84}
85.ext-site-icon-fallback {
86 display: flex;
87 align-items: center;
88 justify-content: center;
89 color: var(--vp-c-text-3);
90 width: 18px;
91 height: 18px;
92}
93.ext-site-icon-loading {
94 background-color: var(--vp-c-bg-mute, var(--vp-c-bg-soft));
95 border-radius: 4px;
96}
97</style>
docs/.vitepress/theme/components/extrepo/RatingFilter.vue deleted −234
@@ -1,234 +0,0 @@
1<script setup lang="ts">
2import { NuInputHighlight, NuVerticalTransition } from '@nolebase/ui'
3import { computed, onMounted, onUnmounted, ref } from 'vue'
4import MenuHelp from '../settings/MenuHelp.vue'
5import MenuTitle from '../settings/MenuTitle.vue'
6import type { RatingFilter } from './types'
7
8const props = defineProps<{
9 modelValue: RatingFilter
10 hasSuggestive: boolean
11}>()
12
13const emit = defineEmits<{
14 'update:modelValue': [value: RatingFilter]
15}>()
16
17const options = computed(() => {
18 const base = [
19 { value: 'all' as RatingFilter, label: 'All' },
20 { value: 'safe' as RatingFilter, label: 'Safe' }
21 ]
22 if (props.hasSuggestive) {
23 base.push({ value: 'suggestive' as RatingFilter, label: 'Mature' })
24 }
25 base.push({
26 value: 'nsfw' as RatingFilter,
27 label: props.hasSuggestive ? 'Adult' : 'NSFW'
28 })
29 return base
30})
31
32const rootRef = ref<HTMLElement>()
33const open = ref(false)
34const menuTitleElementRef = ref<HTMLDivElement>()
35const isMenuHelpPoppedUp = ref(false)
36
37const currentLabel = computed(() => options.value.find(o => o.value === props.modelValue)?.label ?? 'All')
38
39function select(value: RatingFilter) {
40 emit('update:modelValue', value)
41 open.value = false
42}
43
44function onDocClick(e: MouseEvent) {
45 if (rootRef.value && !rootRef.value.contains(e.target as Node)) open.value = false
46}
47
48onMounted(() => document.addEventListener('click', onDocClick, true))
49onUnmounted(() => document.removeEventListener('click', onDocClick, true))
50</script>
51
52<template>
53 <div ref="rootRef" class="ext-rating-select" :class="{ 'ext-rating-select--open': open }">
54 <div ref="menuTitleElementRef" relative flex items-center mb-2>
55 <MenuTitle title="Rating" aria-label="Rating" flex="1" pr-4>
56 <template #icon>
57 <span i-lucide:shield mr-1 aria-hidden="true" />
58 </template>
59 </MenuTitle>
60 <MenuHelp
61 v-model:is-popped-up="isMenuHelpPoppedUp"
62 :menu-title-element-ref="menuTitleElementRef"
63 >
64 <h4 text-md mb-1 font-semibold>Rating</h4>
65 <p text="sm" mb-2>Choose the highest content rating to include.</p>
66 <div class="rating-help-options">
67 <div class="rating-help-option">
68 <strong>All</strong>
69 <span>Shows entries at every rating level</span>
70 </div>
71 <div class="rating-help-option">
72 <strong>Safe</strong>
73 <span>Only entries with no mature content</span>
74 </div>
75 <div v-if="hasSuggestive" class="rating-help-option">
76 <strong>Mature</strong>
77 <span>Includes suggestive content</span>
78 </div>
79 <div class="rating-help-option">
80 <strong>{{ hasSuggestive ? 'Adult' : 'NSFW' }}</strong>
81 <span>Includes explicit adult content</span>
82 </div>
83 </div>
84 </MenuHelp>
85 </div>
86 <NuInputHighlight :active="isMenuHelpPoppedUp" class="rounded-md">
87 <button
88 type="button"
89 class="ext-rating-trigger"
90 aria-haspopup="listbox"
91 :aria-expanded="open"
92 @click="open = !open"
93 >
94 <span class="ext-rating-label">{{ currentLabel }}</span>
95 <span class="ext-rating-chevron i-lucide:chevron-down" :class="{ 'ext-rating-chevron--open': open }" />
96 </button>
97
98 <NuVerticalTransition :duration="200">
99 <div v-show="open" class="ext-rating-options" role="listbox">
100 <button
101 v-for="option in options"
102 :key="option.value"
103 type="button"
104 role="option"
105 class="ext-rating-option"
106 :class="{ 'ext-rating-option--selected': modelValue === option.value }"
107 :aria-selected="modelValue === option.value"
108 @click="select(option.value)"
109 >
110 <span class="ext-rating-option-label">{{ option.label }}</span>
111 </button>
112 </div>
113 </NuVerticalTransition>
114 </NuInputHighlight>
115 </div>
116</template>
117
118<style scoped>
119.rating-help-options {
120 display: flex;
121 flex-direction: column;
122 gap: 5px;
123}
124
125.rating-help-option {
126 display: flex;
127 flex-direction: column;
128 gap: 4px;
129 background: var(--wk-c-menu-bg);
130 border-radius: 12px;
131 padding: 10px 12px;
132}
133
134.rating-help-option strong {
135 font-size: 0.875rem;
136 font-weight: 600;
137 color: var(--vp-c-text-1);
138}
139
140.rating-help-option span {
141 font-size: 0.875rem;
142 color: var(--vp-c-text-2);
143 line-height: 1.4;
144}
145
146.ext-rating-select {
147 position: relative;
148}
149
150.ext-rating-trigger {
151 display: flex;
152 align-items: center;
153 gap: 8px;
154 width: 100%;
155 min-height: 44px;
156 padding: 7px 10px;
157 border-radius: 8px;
158 border: 2px solid var(--vp-c-divider);
159 background: var(--wk-c-menu-bg);
160 color: var(--vp-c-text-1);
161 font-size: 13px;
162 cursor: pointer;
163 transition: border-color 0.15s, background-color 0.15s;
164}
165
166.ext-rating-trigger:hover,
167.ext-rating-select--open .ext-rating-trigger {
168 border-color: var(--vp-c-brand-1);
169}
170
171.ext-rating-label {
172 flex: 1;
173 text-align: left;
174}
175
176.ext-rating-chevron {
177 flex-shrink: 0;
178 color: var(--vp-c-text-2);
179 transition: transform 0.2s ease;
180}
181
182.ext-rating-chevron--open {
183 transform: rotate(180deg);
184}
185
186.ext-rating-options {
187 margin-top: 6px;
188 max-height: 240px;
189 overflow-y: auto;
190 overscroll-behavior: contain;
191 display: flex;
192 flex-direction: column;
193 gap: 2px;
194 padding: 4px;
195 border-radius: 8px;
196 border: 1px solid var(--vp-c-divider);
197 background: var(--vp-c-bg-elv);
198 box-shadow: var(--vp-shadow-2, 0 4px 16px rgba(0, 0, 0, 0.2));
199}
200
201.ext-rating-option {
202 display: flex;
203 align-items: center;
204 gap: 8px;
205 padding: 5px 8px;
206 border-radius: 8px;
207 border: none;
208 background: transparent;
209 cursor: pointer;
210 color: var(--vp-c-text-1);
211 font-size: 13px;
212 text-align: left;
213 width: 100%;
214 transition: background-color 0.15s;
215}
216
217.ext-rating-option-label {
218 flex: 1;
219 min-width: 0;
220}
221
222.ext-rating-option:hover {
223 background-color: var(--vp-c-bg-soft);
224}
225
226.ext-rating-option--selected {
227 background-color: var(--vp-c-brand-soft);
228 font-weight: 600;
229}
230
231.ext-rating-option--selected:hover {
232 background-color: var(--vp-c-brand-soft);
233}
234</style>
docs/.vitepress/theme/components/extrepo/RepoRow.vue +101 −210
@@ -1,15 +1,28 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { computed, ref } from 'vue' 2import { computed, ref } from 'vue'
3import { data } from '../../../../ext/extensionRepos.data' 3import { NOT_EXPANDABLE_REPOS } from './constants'
4import { stripHtml } from './helpers' 4import { stripHtml } from './helpers'
5import { copyValue, hasBrowseOnlyCopyButton, hasCopyButton, installHref, isBrowseOnly, mangayomiCopyValue, mangayomiHref, mangayomiLiveContainerHref } from './install' 5import {
6 copyValue,
7 hasCopyButton,
8 installHref,
9 isBrowseOnly,
10 mangayomiCopyValue,
11 mangayomiHref,
12 mangayomiLiveContainerHref
13} from './install'
14import RepoVariantRow from './RepoVariantRow.vue'
6import SiteGrid from './SiteGrid.vue' 15import SiteGrid from './SiteGrid.vue'
7import type { Repo, RepoVariant } from './types' 16import type { Repo } from './types'
17import { useCopy } from './useCopy'
18import { useRepoStore } from './useRepoStore'
8import { useTooltip } from './useTooltip' 19import { useTooltip } from './useTooltip'
9 20
10const { show: showTooltip, hide: hideTooltip } = useTooltip() 21const { show: showTooltip, hide: hideTooltip } = useTooltip()
22const { copiedKey, copy } = useCopy()
23const { store } = useRepoStore()
11 24
12const repoData = data.sites 25const repoData = computed(() => store.value?.sites ?? {})
13 26
14const props = defineProps<{ 27const props = defineProps<{
15 repo: Repo 28 repo: Repo
@@ -17,60 +30,51 @@ const props = defineProps<{
17 showBroken?: boolean 30 showBroken?: boolean
18}>() 31}>()
19 32
20const NOT_EXPANDABLE = new Set(['MegaRepo', 'Shotetsu Compatability'])
21
22const open = ref(false) 33const open = ref(false)
23const copied = ref(false)
24const copiedLabel = ref<string | null>(null)
25const openVariants = ref<Set<string>>(new Set())
26 34
27const sites = computed(() => { 35const sites = computed(() => {
28 const dataUrl = props.repo.data ?? props.repo.indexUrl 36 const dataUrl = props.repo.data ?? props.repo.indexUrl
29 const all = repoData[dataUrl]?.sites ?? [] 37 const all = repoData.value[dataUrl]?.sites ?? []
30 return props.showBroken ? all : all.filter(site => !site.isBroken) 38 return props.showBroken ? all : all.filter(site => !site.isBroken)
31}) 39})
32const isExpandable = computed(() => !NOT_EXPANDABLE.has(stripHtml(props.repo.name))) 40const repoName = computed(() => stripHtml(props.repo.name))
33const installUrl = computed(() => installHref(props.scheme, props.repo, { 41const isExpandable = computed(() => !NOT_EXPANDABLE_REPOS.has(repoName.value))
34 suwatteV6: repoData[props.repo.indexUrl]?.suwatteV6, 42const installUrl = computed(() =>
35 suwatteListUrl: repoData[props.repo.indexUrl]?.suwatteListUrl 43 installHref(props.scheme, props.repo, {
36})) 44 suwatteV6: repoData.value[props.repo.indexUrl]?.suwatteV6,
37// Browse-only schemes (e.g. Kotatsu forks) have no app to deep-link into, so install, 45 suwatteListUrl: repoData.value[props.repo.indexUrl]?.suwatteListUrl
38// copy, and livecontainer actions are hidden everywhere in this component. 46 })
47)
39const showActions = computed(() => !isBrowseOnly(props.scheme)) 48const showActions = computed(() => !isBrowseOnly(props.scheme))
40 49
41// First variant is the combined "All-in-One" one (when 2+ types exist), shown directly 50const headerVariant = computed(() =>
42// on the repo header; remaining variants list below as their own collapsible sub-rows. 51 showActions.value ? props.repo.variants?.[0] : undefined
43// Browse-only groups have no such combined header since the builds share nothing to 52)
44// combine, so every variant renders as a sub-row instead. 53const headerCopyValue = computed(() =>
45const headerVariant = computed(() => showActions.value ? props.repo.variants?.[0] : undefined) 54 headerVariant.value ? mangayomiCopyValue(headerVariant.value) : null
55)
56const headerInstallUrl = computed(() =>
57 headerVariant.value ? mangayomiHref(props.repo, headerVariant.value) : null
58)
59const headerLiveUrl = computed(() =>
60 headerVariant.value
61 ? mangayomiLiveContainerHref(props.repo, headerVariant.value)
62 : null
63)
46const subVariants = computed(() => { 64const subVariants = computed(() => {
47 if (!props.repo.variants?.length) return [] 65 if (!props.repo.variants?.length) return []
48 return showActions.value && props.repo.variants.length > 1 ? props.repo.variants.slice(1) : props.repo.variants 66 return showActions.value && props.repo.variants.length > 1
67 ? props.repo.variants.slice(1)
68 : props.repo.variants
49}) 69})
50 70
51async function copyUrl() { 71async function copyUrl() {
52 await navigator.clipboard.writeText(copyValue(props.scheme, props.repo.indexUrl)) 72 await copy(props.repo.indexUrl, copyValue(props.scheme, props.repo.indexUrl))
53 copied.value = true
54 setTimeout(() => { copied.value = false }, 1500)
55}
56
57async function copyVariantUrl(variant: RepoVariant) {
58 const value = mangayomiCopyValue(variant)
59 if (!value) return
60 await navigator.clipboard.writeText(value)
61 copiedLabel.value = variant.label
62 setTimeout(() => { if (copiedLabel.value === variant.label) copiedLabel.value = null }, 1500)
63} 73}
64 74
65function toggleVariant(label: string) { 75async function copyHeaderVariantUrl() {
66 if (openVariants.value.has(label)) openVariants.value.delete(label) 76 if (!headerVariant.value || !headerCopyValue.value) return
67 else openVariants.value.add(label) 77 await copy(headerVariant.value.label, headerCopyValue.value)
68}
69
70function variantSites(variant: RepoVariant) {
71 const url = mangayomiCopyValue(variant)
72 const all = url ? repoData[url]?.sites ?? [] : []
73 return props.showBroken ? all : all.filter(site => !site.isBroken)
74} 78}
75</script> 79</script>
76 80
@@ -90,44 +94,66 @@ function variantSites(variant: RepoVariant) {
90 </div> 94 </div>
91 <div class="ext-repo-actions"> 95 <div class="ext-repo-actions">
92 <template v-if="headerVariant"> 96 <template v-if="headerVariant">
93 <a class="ext-btn ext-btn-install" :href="mangayomiHref(repo, headerVariant)"> 97 <a class="ext-btn ext-btn-install" :href="headerInstallUrl!">
94 <span class="i-lucide:download" /> 98 <span class="i-lucide:download" />
95 <span class="ext-btn-install-label">Install</span> 99 <span class="ext-btn-install-label">Install</span>
96 </a> 100 </a>
97 <a class="ext-btn ext-btn-livecontainer" :href="mangayomiLiveContainerHref(repo, headerVariant)" aria-label="Install via LiveContainer (iOS)" @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')" @mouseleave="hideTooltip"> 101 <a
102 class="ext-btn ext-btn-livecontainer"
103 :href="headerLiveUrl!"
104 aria-label="Install via LiveContainer (iOS)"
105 @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')"
106 @mouseleave="hideTooltip"
107 >
98 <span class="i-mdi:apple" /> 108 <span class="i-mdi:apple" />
99 </a> 109 </a>
100 <button 110 <button
101 v-if="mangayomiCopyValue(headerVariant)" 111 v-if="headerCopyValue"
102 class="ext-btn ext-btn-copy" 112 class="ext-btn ext-btn-copy"
103 type="button" 113 type="button"
104 @click="copyVariantUrl(headerVariant)" 114 @click="copyHeaderVariantUrl"
105 > 115 >
106 <span v-if="copiedLabel === headerVariant.label" class="i-lucide:check" /> 116 <span
117 v-if="copiedKey === headerVariant.label"
118 class="i-lucide:check"
119 />
107 <span v-else class="i-lucide:copy" /> 120 <span v-else class="i-lucide:copy" />
108 </button> 121 </button>
109 <!-- Invisible spacers so the header's action group lines up with the sub-rows' --> 122 <button
110 <button v-if="!mangayomiCopyValue(headerVariant)" class="ext-btn ext-btn-copy ext-btn-spacer" tabindex="-1" aria-hidden="true"> 123 v-else
124 class="ext-btn ext-btn-copy ext-btn-spacer"
125 tabindex="-1"
126 aria-hidden="true"
127 >
111 <span class="i-lucide:copy" /> 128 <span class="i-lucide:copy" />
112 </button> 129 </button>
113 <button class="ext-btn ext-btn-toggle ext-btn-spacer" tabindex="-1" aria-hidden="true"> 130 <button
131 class="ext-btn ext-btn-toggle ext-btn-spacer"
132 tabindex="-1"
133 aria-hidden="true"
134 >
114 <span class="i-lucide:chevron-down" /> 135 <span class="i-lucide:chevron-down" />
115 </button> 136 </button>
116 </template> 137 </template>
117 <template v-else-if="showActions"> 138 <template v-else-if="showActions">
118 <a v-if="installUrl" class="ext-btn ext-btn-install" :href="installUrl"> 139 <a
140 v-if="installUrl"
141 class="ext-btn ext-btn-install"
142 :href="installUrl"
143 >
119 <span class="i-lucide:download" /> 144 <span class="i-lucide:download" />
120 <span class="ext-btn-install-label">Install</span> 145 <span class="ext-btn-install-label">Install</span>
121 </a> 146 </a>
122 <button v-if="hasCopyButton(scheme)" class="ext-btn ext-btn-copy" type="button" @click="copyUrl"> 147 <button
123 <span v-if="copied" class="i-lucide:check" /> 148 v-if="hasCopyButton(scheme)"
149 class="ext-btn ext-btn-copy"
150 type="button"
151 @click="copyUrl"
152 >
153 <span v-if="copiedKey === repo.indexUrl" class="i-lucide:check" />
124 <span v-else class="i-lucide:copy" /> 154 <span v-else class="i-lucide:copy" />
125 </button> 155 </button>
126 </template> 156 </template>
127 <button v-else-if="hasBrowseOnlyCopyButton(scheme)" class="ext-btn ext-btn-copy" type="button" @click="copyUrl">
128 <span v-if="copied" class="i-lucide:check" />
129 <span v-else class="i-lucide:copy" />
130 </button>
131 <button 157 <button
132 v-if="!repo.variants" 158 v-if="!repo.variants"
133 class="ext-btn ext-btn-toggle" 159 class="ext-btn ext-btn-toggle"
@@ -144,62 +170,32 @@ function variantSites(variant: RepoVariant) {
144 </div> 170 </div>
145 171
146 <div v-if="subVariants.length" class="ext-repo-variants"> 172 <div v-if="subVariants.length" class="ext-repo-variants">
147 <div v-for="variant in subVariants" :key="variant.label" class="ext-repo-variant"> 173 <RepoVariantRow
148 <div class="ext-repo-variant-row"> 174 v-for="variant in subVariants"
149 <span class="ext-repo-variant-label">{{ variant.label }}</span> 175 :key="variant.label"
150 <div class="ext-repo-actions"> 176 :repo="repo"
151 <template v-if="showActions"> 177 :variant="variant"
152 <a class="ext-btn ext-btn-install" :href="mangayomiHref(repo, variant)"> 178 :scheme="scheme"
153 <span class="i-lucide:download" /> 179 :show-actions="showActions"
154 <span class="ext-btn-install-label">Install</span> 180 :show-broken="showBroken"
155 </a> 181 />
156 <a class="ext-btn ext-btn-livecontainer" :href="mangayomiLiveContainerHref(repo, variant)" aria-label="Install via LiveContainer (iOS)" @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')" @mouseleave="hideTooltip">
157 <span class="i-mdi:apple" />
158 </a>
159 <button
160 v-if="mangayomiCopyValue(variant)"
161 class="ext-btn ext-btn-copy"
162 type="button"
163 @click="copyVariantUrl(variant)"
164 >
165 <span v-if="copiedLabel === variant.label" class="i-lucide:check" />
166 <span v-else class="i-lucide:copy" />
167 </button>
168 </template>
169 <button
170 v-else-if="mangayomiCopyValue(variant)"
171 class="ext-btn ext-btn-copy"
172 type="button"
173 @click="copyVariantUrl(variant)"
174 >
175 <span v-if="copiedLabel === variant.label" class="i-lucide:check" />
176 <span v-else class="i-lucide:copy" />
177 </button>
178 <button
179 class="ext-btn ext-btn-toggle"
180 type="button"
181 :class="{ open: openVariants.has(variant.label) }"
182 :aria-expanded="openVariants.has(variant.label)"
183 @click="toggleVariant(variant.label)"
184 >
185 <span class="i-lucide:chevron-down" />
186 </button>
187 </div>
188 </div>
189
190 <SiteGrid v-if="openVariants.has(variant.label)" :sites="variantSites(variant)" :scheme="scheme" empty-text="No site data available." />
191 </div>
192 </div> 182 </div>
193 183
194 <SiteGrid v-if="!repo.variants && isExpandable && open" :sites="sites" :scheme="scheme" empty-text="No site data available." /> 184 <SiteGrid
185 v-if="!repo.variants && isExpandable && open"
186 :sites="sites"
187 :scheme="scheme"
188 empty-text="No site data available."
189 />
195 </div> 190 </div>
196</template> 191</template>
197 192
193<style scoped src="./repoRowShared.css"></style>
194
198<style scoped> 195<style scoped>
199.ext-repo + .ext-repo { 196.ext-repo + .ext-repo {
200 border-top: 1px solid var(--vp-c-divider); 197 border-top: 1px solid var(--vp-c-divider);
201} 198}
202
203.ext-repo-row { 199.ext-repo-row {
204 display: flex; 200 display: flex;
205 align-items: center; 201 align-items: center;
@@ -208,7 +204,6 @@ function variantSites(variant: RepoVariant) {
208 padding: 10px 14px; 204 padding: 10px 14px;
209 background-color: var(--vp-c-bg-soft); 205 background-color: var(--vp-c-bg-soft);
210} 206}
211
212.ext-repo-name { 207.ext-repo-name {
213 font-size: 14px; 208 font-size: 14px;
214 font-weight: 600; 209 font-weight: 600;
@@ -218,11 +213,9 @@ function variantSites(variant: RepoVariant) {
218 gap: 6px; 213 gap: 6px;
219 min-width: 0; 214 min-width: 0;
220} 215}
221
222.ext-repo-name :deep(a) { 216.ext-repo-name :deep(a) {
223 color: inherit; 217 color: inherit;
224} 218}
225
226.ext-note-btn { 219.ext-note-btn {
227 display: inline-flex; 220 display: inline-flex;
228 align-items: center; 221 align-items: center;
@@ -236,12 +229,10 @@ function variantSites(variant: RepoVariant) {
236 line-height: 0; 229 line-height: 0;
237 flex-shrink: 0; 230 flex-shrink: 0;
238} 231}
239
240.ext-note-btn span { 232.ext-note-btn span {
241 font-size: 13px; 233 font-size: 13px;
242 vertical-align: 0; 234 vertical-align: 0;
243} 235}
244
245.ext-note-popper { 236.ext-note-popper {
246 max-width: 280px; 237 max-width: 280px;
247 padding: 10px 12px; 238 padding: 10px 12px;
@@ -254,108 +245,8 @@ function variantSites(variant: RepoVariant) {
254 line-height: 1.5; 245 line-height: 1.5;
255 color: var(--vp-c-text-2); 246 color: var(--vp-c-text-2);
256} 247}
257
258.ext-repo-actions {
259 display: flex;
260 align-items: center;
261 gap: 6px;
262 flex-shrink: 0;
263}
264
265.ext-btn {
266 display: inline-flex;
267 align-items: center;
268 gap: 4px;
269 padding: 5px 10px;
270 border-radius: 8px;
271 border: 1px solid var(--vp-c-divider);
272 background-color: var(--vp-c-bg);
273 color: var(--vp-c-text-1);
274 font-size: 13px;
275 line-height: 1;
276 cursor: pointer;
277 transition: border-color 0.2s, background-color 0.2s, color 0.2s;
278}
279
280.ext-btn:hover {
281 border-color: var(--vp-c-brand-1);
282}
283
284.ext-btn-install {
285 background-color: var(--vp-button-brand-bg);
286 color: var(--vp-button-brand-text) !important;
287 border-color: var(--vp-button-brand-border);
288 text-decoration: none !important;
289 font-weight: 600;
290}
291
292.ext-btn-install:hover {
293 filter: brightness(1.08);
294 border-color: var(--vp-button-brand-hover-border);
295}
296
297.ext-btn-copy,
298.ext-btn-livecontainer {
299 padding: 5px 8px;
300}
301
302.ext-btn-toggle {
303 padding: 0;
304 border: none;
305 background: transparent;
306 color: var(--vp-c-text-1);
307}
308
309.ext-btn-toggle:hover {
310 border-color: transparent;
311 color: var(--vp-c-brand-1);
312}
313
314.ext-btn-toggle span {
315 font-size: 18px;
316 transition: transform 0.2s;
317}
318
319.ext-btn-toggle.open span {
320 transform: rotate(180deg);
321}
322
323.ext-btn-toggle-hidden {
324 visibility: hidden;
325 pointer-events: none;
326}
327
328.ext-btn-spacer {
329 visibility: hidden;
330 pointer-events: none;
331}
332
333.ext-repo-variants { 248.ext-repo-variants {
334 display: flex; 249 display: flex;
335 flex-direction: column; 250 flex-direction: column;
336} 251}
337
338.ext-repo-variant-row {
339 display: flex;
340 align-items: center;
341 justify-content: space-between;
342 gap: 12px;
343 padding: 8px 14px 8px 28px;
344 border-top: 1px solid var(--vp-c-divider);
345}
346
347.ext-repo-variant-label {
348 font-size: 13px;
349 color: var(--vp-c-text-2);
350}
351
352@media (max-width: 767px) {
353 .ext-btn-install {
354 padding: 5px 8px;
355 }
356
357 .ext-btn-install-label {
358 display: none;
359 }
360}
361</style> 252</style>
docs/.vitepress/theme/components/extrepo/RepoVariantRow.vue added +121
@@ -0,0 +1,121 @@
1<script setup lang="ts">
2import { computed, ref } from 'vue'
3import {
4 mangayomiCopyValue,
5 mangayomiHref,
6 mangayomiLiveContainerHref
7} from './install'
8import SiteGrid from './SiteGrid.vue'
9import type { Repo, RepoVariant } from './types'
10import { useCopy } from './useCopy'
11import { useRepoStore } from './useRepoStore'
12import { useTooltip } from './useTooltip'
13
14const { show: showTooltip, hide: hideTooltip } = useTooltip()
15const { copiedKey, copy } = useCopy()
16const { store } = useRepoStore()
17
18const repoData = computed(() => store.value?.sites ?? {})
19
20const props = defineProps<{
21 repo: Repo
22 variant: RepoVariant
23 scheme: string
24 showActions: boolean
25 showBroken?: boolean
26}>()
27
28const open = ref(false)
29const copyValue = computed(() => mangayomiCopyValue(props.variant))
30const installUrl = computed(() => mangayomiHref(props.repo, props.variant))
31const liveUrl = computed(() =>
32 mangayomiLiveContainerHref(props.repo, props.variant)
33)
34
35const sites = computed(() => {
36 const url = copyValue.value
37 const all = url ? repoData.value[url]?.sites ?? [] : []
38 return props.showBroken ? all : all.filter(site => !site.isBroken)
39})
40
41async function copyVariantUrl() {
42 if (!copyValue.value) return
43 await copy(props.variant.label, copyValue.value)
44}
45</script>
46
47<template>
48 <div class="ext-repo-variant">
49 <div class="ext-repo-variant-row">
50 <span class="ext-repo-variant-label">{{ variant.label }}</span>
51 <div class="ext-repo-actions">
52 <template v-if="showActions">
53 <a class="ext-btn ext-btn-install" :href="installUrl">
54 <span class="i-lucide:download" />
55 <span class="ext-btn-install-label">Install</span>
56 </a>
57 <a
58 class="ext-btn ext-btn-livecontainer"
59 :href="liveUrl"
60 aria-label="Install via LiveContainer (iOS)"
61 @mouseenter="showTooltip($event, 'Install via LiveContainer (iOS)')"
62 @mouseleave="hideTooltip"
63 >
64 <span class="i-mdi:apple" />
65 </a>
66 <button
67 v-if="copyValue"
68 class="ext-btn ext-btn-copy"
69 type="button"
70 @click="copyVariantUrl"
71 >
72 <span v-if="copiedKey === variant.label" class="i-lucide:check" />
73 <span v-else class="i-lucide:copy" />
74 </button>
75 </template>
76 <button
77 v-else-if="copyValue"
78 class="ext-btn ext-btn-copy"
79 type="button"
80 @click="copyVariantUrl"
81 >
82 <span v-if="copiedKey === variant.label" class="i-lucide:check" />
83 <span v-else class="i-lucide:copy" />
84 </button>
85 <button
86 class="ext-btn ext-btn-toggle"
87 type="button"
88 :class="{ open }"
89 :aria-expanded="open"
90 @click="open = !open"
91 >
92 <span class="i-lucide:chevron-down" />
93 </button>
94 </div>
95 </div>
96
97 <SiteGrid
98 v-if="open"
99 :sites="sites"
100 :scheme="scheme"
101 empty-text="No site data available."
102 />
103 </div>
104</template>
105
106<style scoped src="./repoRowShared.css"></style>
107
108<style scoped>
109.ext-repo-variant-row {
110 display: flex;
111 align-items: center;
112 justify-content: space-between;
113 gap: 12px;
114 padding: 8px 14px 8px 28px;
115 border-top: 1px solid var(--vp-c-divider);
116}
117.ext-repo-variant-label {
118 font-size: 13px;
119 color: var(--vp-c-text-2);
120}
121</style>
docs/.vitepress/theme/components/extrepo/SettingsMenu.vue +133 −61
@@ -1,13 +1,11 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { nextTick, onMounted, onUnmounted, ref } from 'vue' 2import { computed, nextTick, onMounted, onUnmounted, ref } from 'vue'
3import BrokenFilter from './BrokenFilter.vue' 3import BrokenFilter from './BrokenFilter.vue'
4import ContentTypeFilter from './ContentTypeFilter.vue' 4import FilterSelect, { type FilterOption } from './FilterSelect.vue'
5import LangSelect from './LangSelect.vue' 5import { contentTypeLabel, langFlagClass, langLabel } from './helpers'
6import RatingFilter from './RatingFilter.vue'
7import TypeSelect from './TypeSelect.vue'
8import type { RatingFilter as RatingFilterValue } from './types' 6import type { RatingFilter as RatingFilterValue } from './types'
9 7
10defineProps<{ 8const props = defineProps<{
11 langFilter: string 9 langFilter: string
12 ratingFilter: RatingFilterValue 10 ratingFilter: RatingFilterValue
13 availableLangs: string[] 11 availableLangs: string[]
@@ -17,12 +15,6 @@ defineProps<{
17 contentTypeFilter: string 15 contentTypeFilter: string
18 availableContentTypes: string[] 16 availableContentTypes: string[]
19 hasContentTypes: boolean 17 hasContentTypes: boolean
20 streamTypeFilter: Set<string>
21 availableStreamTypes: string[]
22 hasStreamTypes: boolean
23 qualityFilter: Set<string>
24 availableQualities: string[]
25 hasQualities: boolean
26 showBroken: boolean 18 showBroken: boolean
27 hasBroken: boolean 19 hasBroken: boolean
28}>() 20}>()
@@ -31,8 +23,6 @@ defineEmits<{
31 'update:langFilter': [value: string] 23 'update:langFilter': [value: string]
32 'update:ratingFilter': [value: RatingFilterValue] 24 'update:ratingFilter': [value: RatingFilterValue]
33 'update:contentTypeFilter': [value: string] 25 'update:contentTypeFilter': [value: string]
34 'update:streamTypeFilter': [value: Set<string>]
35 'update:qualityFilter': [value: Set<string>]
36 'update:showBroken': [value: boolean] 26 'update:showBroken': [value: boolean]
37}>() 27}>()
38 28
@@ -41,18 +31,23 @@ const btnRef = ref<HTMLElement>()
41const menuRef = ref<HTMLElement>() 31const menuRef = ref<HTMLElement>()
42const open = ref(false) 32const open = ref(false)
43const menuStyle = ref<Record<string, string>>({}) 33const menuStyle = ref<Record<string, string>>({})
34let raf = 0
44 35
45function updatePosition() { 36function updatePosition() {
46 if (!btnRef.value) return 37 if (!btnRef.value) return
47
48 const viewportMargin = 12 38 const viewportMargin = 12
49 const menuWidth = menuRef.value?.offsetWidth ?? 260 39 const menuWidth = menuRef.value?.offsetWidth ?? 260
50 const btnRect = btnRef.value.getBoundingClientRect() 40 const btnRect = btnRef.value.getBoundingClientRect()
51 const maxLeft = Math.max(viewportMargin, window.innerWidth - viewportMargin - menuWidth) 41 const maxLeft = Math.max(
52 const left = Math.min(Math.max(btnRect.right - menuWidth, viewportMargin), maxLeft) 42 viewportMargin,
43 window.innerWidth - viewportMargin - menuWidth
44 )
45 const left = Math.min(
46 Math.max(btnRect.right - menuWidth, viewportMargin),
47 maxLeft
48 )
53 const maxTop = Math.max(viewportMargin, window.innerHeight - viewportMargin) 49 const maxTop = Math.max(viewportMargin, window.innerHeight - viewportMargin)
54 const top = Math.min(btnRect.bottom + 6, maxTop) 50 const top = Math.min(btnRect.bottom + 6, maxTop)
55
56 menuStyle.value = { top: `${top}px`, left: `${left}px` } 51 menuStyle.value = { top: `${top}px`, left: `${left}px` }
57} 52}
58 53
@@ -64,28 +59,74 @@ function toggle() {
64function onDocClick(e: MouseEvent) { 59function onDocClick(e: MouseEvent) {
65 const target = e.target as Node 60 const target = e.target as Node
66 if ( 61 if (
67 rootRef.value && !rootRef.value.contains(target) 62 rootRef.value && !rootRef.value.contains(target) &&
68 && menuRef.value && !menuRef.value.contains(target) 63 menuRef.value && !menuRef.value.contains(target)
69 ) { 64 ) {
70 open.value = false 65 open.value = false
71 } 66 }
72} 67}
73 68
74function onReposition() { 69function onReposition() {
75 if (open.value) updatePosition() 70 if (!open.value || raf) return
71 raf = requestAnimationFrame(() => {
72 raf = 0
73 updatePosition()
74 })
76} 75}
77 76
78onMounted(() => { 77onMounted(() => {
79 document.addEventListener('click', onDocClick, true) 78 document.addEventListener('click', onDocClick, true)
80 window.addEventListener('resize', onReposition) 79 window.addEventListener('resize', onReposition, { passive: true })
81 window.addEventListener('scroll', onReposition, true) 80 window.addEventListener('scroll', onReposition, {
81 capture: true,
82 passive: true
83 })
82}) 84})
83 85
84onUnmounted(() => { 86onUnmounted(() => {
85 document.removeEventListener('click', onDocClick, true) 87 document.removeEventListener('click', onDocClick, true)
86 window.removeEventListener('resize', onReposition) 88 window.removeEventListener('resize', onReposition)
87 window.removeEventListener('scroll', onReposition, true) 89 window.removeEventListener('scroll', onReposition, true)
90 if (raf) cancelAnimationFrame(raf)
88}) 91})
92
93const langOptions = computed<FilterOption[]>(() => [
94 { value: '', label: 'All languages' },
95 ...(props.hasMultiLanguage
96 ? [{ value: 'all', label: 'Multi-language', flag: langFlagClass('all') }]
97 : []),
98 ...props.availableLangs.map(lang => ({
99 value: lang,
100 label: langLabel(lang),
101 flag: langFlagClass(lang)
102 }))
103])
104const langTrigger = computed(() =>
105 props.langFilter ? langLabel(props.langFilter) : 'All languages'
106)
107
108const ratingOptions = computed<FilterOption[]>(() => {
109 const opts: FilterOption[] = [
110 { value: 'all', label: 'All' },
111 { value: 'safe', label: 'Safe' }
112 ]
113 if (props.hasSuggestive) opts.push({ value: 'suggestive', label: 'Mature' })
114 opts.push({ value: 'nsfw', label: props.hasSuggestive ? 'Adult' : 'NSFW' })
115 return opts
116})
117
118const typeOptions = computed<FilterOption[]>(() => [
119 { value: '', label: 'All types' },
120 ...props.availableContentTypes.map(t => ({
121 value: t,
122 label: contentTypeLabel(t)
123 }))
124])
125const typeTrigger = computed(() =>
126 props.contentTypeFilter
127 ? contentTypeLabel(props.contentTypeFilter)
128 : 'All types'
129)
89</script> 130</script>
90 131
91<template> 132<template>
@@ -107,46 +148,61 @@ onUnmounted(() => {
107 v-show="open" 148 v-show="open"
108 ref="menuRef" 149 ref="menuRef"
109 class="ext-settings-menu VPMenu" 150 class="ext-settings-menu VPMenu"
110 :class="{ 'ext-settings-menu--wide': hasSuggestive || hasContentTypes || hasStreamTypes || hasQualities }" 151 :class="{
152 'ext-settings-menu--wide': hasSuggestive || hasContentTypes
153 }"
111 :style="menuStyle" 154 :style="menuStyle"
112 > 155 >
113 <LangSelect 156 <FilterSelect
114 v-if="availableLangs.length > 0" 157 v-if="availableLangs.length > 0"
115 :model-value="langFilter" 158 :model-value="langFilter"
116 :available-langs="availableLangs" 159 :options="langOptions"
117 :has-multi-language="hasMultiLanguage" 160 :trigger-label="langTrigger"
161 title="Language"
162 icon="i-lucide:languages"
163 help-text="Filters extensions by translated language (not original language)."
118 @update:model-value="$emit('update:langFilter', $event)" 164 @update:model-value="$emit('update:langFilter', $event)"
119 /> 165 />
120 <RatingFilter 166 <FilterSelect
121 v-if="hasRatings" 167 v-if="hasRatings"
122 :model-value="ratingFilter" 168 :model-value="ratingFilter"
123 :has-suggestive="hasSuggestive" 169 :options="ratingOptions"
124 @update:model-value="$emit('update:ratingFilter', $event)" 170 title="Rating"
125 /> 171 icon="i-lucide:shield"
126 <TypeSelect 172 help-text="Choose the highest content rating to include."
173 @update:model-value="$emit('update:ratingFilter', $event as RatingFilterValue)"
174 >
175 <template #help-extra>
176 <div class="rating-help-options">
177 <div class="rating-help-option">
178 <strong>All</strong>
179 <span>Shows entries at every rating level</span>
180 </div>
181 <div class="rating-help-option">
182 <strong>Safe</strong>
183 <span>Only entries with no mature content</span>
184 </div>
185 <div v-if="hasSuggestive" class="rating-help-option">
186 <strong>Mature</strong>
187 <span>Includes suggestive content</span>
188 </div>
189 <div class="rating-help-option">
190 <strong>{{ hasSuggestive ? 'Adult' : 'NSFW' }}</strong>
191 <span>Includes explicit adult content</span>
192 </div>
193 </div>
194 </template>
195 </FilterSelect>
196 <FilterSelect
127 v-if="hasContentTypes" 197 v-if="hasContentTypes"
128 :model-value="contentTypeFilter" 198 :model-value="contentTypeFilter"
129 :available-types="availableContentTypes" 199 :options="typeOptions"
200 :trigger-label="typeTrigger"
201 title="Type"
202 icon="i-lucide:tags"
203 help-text="Filters extensions by type."
130 @update:model-value="$emit('update:contentTypeFilter', $event)" 204 @update:model-value="$emit('update:contentTypeFilter', $event)"
131 /> 205 />
132 <ContentTypeFilter
133 v-if="hasStreamTypes"
134 :model-value="streamTypeFilter"
135 :available-types="availableStreamTypes"
136 title="Stream Type"
137 icon="i-lucide:cast"
138 help-text="Shows or hides specific stream types. Unchecking a type hides matching entries from the list."
139 @update:model-value="$emit('update:streamTypeFilter', $event)"
140 />
141 <ContentTypeFilter
142 v-if="hasQualities"
143 :model-value="qualityFilter"
144 :available-types="availableQualities"
145 title="Quality"
146 icon="i-lucide:monitor"
147 help-text="Shows or hides specific quality levels. Unchecking a quality hides matching entries from the list."
148 @update:model-value="$emit('update:qualityFilter', $event)"
149 />
150 <BrokenFilter 206 <BrokenFilter
151 v-if="hasBroken" 207 v-if="hasBroken"
152 :model-value="showBroken" 208 :model-value="showBroken"
@@ -161,7 +217,6 @@ onUnmounted(() => {
161.ext-settings { 217.ext-settings {
162 position: relative; 218 position: relative;
163} 219}
164
165.ext-settings-btn { 220.ext-settings-btn {
166 display: flex; 221 display: flex;
167 align-items: center; 222 align-items: center;
@@ -177,32 +232,28 @@ onUnmounted(() => {
177 cursor: pointer; 232 cursor: pointer;
178 transition: opacity 0.25s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); 233 transition: opacity 0.25s, transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
179} 234}
180
181.ext-settings-btn:hover, 235.ext-settings-btn:hover,
182.ext-settings-btn[aria-expanded="true"] { 236.ext-settings-btn[aria-expanded="true"] {
183 color: var(--vp-c-text-1); 237 color: var(--vp-c-text-1);
184 opacity: 1; 238 opacity: 1;
185 background: transparent; 239 background: transparent;
186} 240}
187
188.ext-settings-btn:active { 241.ext-settings-btn:active {
189 transform: scale(0.94); 242 transform: scale(0.94);
190} 243}
191
192.ext-settings-btn span { 244.ext-settings-btn span {
193 font-size: 15px; 245 font-size: 15px;
194} 246}
195
196html.effects-disabled .ext-settings-btn { 247html.effects-disabled .ext-settings-btn {
197 transition: none; 248 transition: none;
198} 249}
199
200html.effects-disabled .ext-settings-btn:active { 250html.effects-disabled .ext-settings-btn:active {
201 transform: none; 251 transform: none;
202} 252}
203
204.ext-settings-menu { 253.ext-settings-menu {
205 --vp-nolebase-enhanced-readabilities-menu-background-color: var(--wk-c-menu-bg); 254 --vp-nolebase-enhanced-readabilities-menu-background-color: var(
255 --wk-c-menu-bg
256 );
206 --vp-nolebase-enhanced-readabilities-menu-text-color: var(--vp-c-text-1); 257 --vp-nolebase-enhanced-readabilities-menu-text-color: var(--vp-c-text-1);
207 position: fixed; 258 position: fixed;
208 z-index: 100; 259 z-index: 100;
@@ -216,12 +267,33 @@ html.effects-disabled .ext-settings-btn:active {
216 background-color: var(--vp-c-bg-elv); 267 background-color: var(--vp-c-bg-elv);
217 box-shadow: var(--vp-shadow-3, 0 4px 16px rgba(0, 0, 0, 0.3)); 268 box-shadow: var(--vp-shadow-3, 0 4px 16px rgba(0, 0, 0, 0.3));
218} 269}
219
220.ext-settings-menu > * + * { 270.ext-settings-menu > * + * {
221 margin-top: 14px; 271 margin-top: 14px;
222} 272}
223
224.ext-settings-menu--wide { 273.ext-settings-menu--wide {
225 width: 320px; 274 width: 320px;
226} 275}
276.rating-help-options {
277 display: flex;
278 flex-direction: column;
279 gap: 5px;
280}
281.rating-help-option {
282 display: flex;
283 flex-direction: column;
284 gap: 4px;
285 background: var(--wk-c-menu-bg);
286 border-radius: 12px;
287 padding: 10px 12px;
288}
289.rating-help-option strong {
290 font-size: 0.875rem;
291 font-weight: 600;
292 color: var(--vp-c-text-1);
293}
294.rating-help-option span {
295 font-size: 0.875rem;
296 color: var(--vp-c-text-2);
297 line-height: 1.4;
298}
227</style> 299</style>
docs/.vitepress/theme/components/extrepo/SiteCell.vue +49 −101
@@ -1,27 +1,23 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { ref } from 'vue'
3import { langFlagClass, ratingIcon, ratingTitle } from './helpers' 2import { langFlagClass, ratingIcon, ratingTitle } from './helpers'
4import { hasCopyButton } from './install' 3import { hasCopyButton } from './install'
5import LazyIcon from './LazyIcon.vue' 4import LazyIcon from './LazyIcon.vue'
6import type { RepoSite } from './types' 5import type { RepoSite } from './types'
6import { useCopy } from './useCopy'
7import { useTooltip } from './useTooltip' 7import { useTooltip } from './useTooltip'
8 8
9const { show: showTooltip, hide: hideTooltip } = useTooltip() 9const { show: showTooltip, hide: hideTooltip } = useTooltip()
10const { copiedKey, copy } = useCopy()
10 11
11const props = defineProps<{ 12const props = defineProps<{
12 site: RepoSite & { repoName?: string } 13 site: RepoSite & { repoName?: string }
13 scheme?: string 14 scheme?: string
14}>() 15}>()
15 16
16const copied = ref(false)
17
18async function copyInstallUrl() { 17async function copyInstallUrl() {
19 const soraMatch = props.site.installUrl?.match(/^sora:\/\/module\?url=(.+)$/) 18 const value = props.site.installUrl
20 const value = soraMatch ? soraMatch[1] : props.site.installUrl
21 if (!value) return 19 if (!value) return
22 await navigator.clipboard.writeText(value) 20 await copy(value, value)
23 copied.value = true
24 setTimeout(() => { copied.value = false }, 1500)
25} 21}
26</script> 22</script>
27 23
@@ -36,23 +32,60 @@ async function copyInstallUrl() {
36 :rel="site.url ? 'noopener noreferrer' : undefined" 32 :rel="site.url ? 'noopener noreferrer' : undefined"
37 > 33 >
38 <div class="ext-site-row"> 34 <div class="ext-site-row">
39 <LazyIcon class="ext-site-icon" :src="site.icon" :alt="site.name" /> 35 <LazyIcon :src="site.icon" :alt="site.name" />
40 <span class="ext-site-name-text" :aria-label="site.name" @mouseenter="showTooltip($event, site.name)" @mouseleave="hideTooltip"><span class="ext-site-name-inner">{{ site.name }}</span></span> 36 <span
41 <span v-if="site.rating !== 'safe'" class="ext-site-nsfw" :class="ratingIcon(site.rating)" :aria-label="ratingTitle(site.rating)" @mouseenter="showTooltip($event, ratingTitle(site.rating))" @mouseleave="hideTooltip" /> 37 class="ext-site-name-text"
42 <span class="ext-site-lang" :class="langFlagClass(site.lang)" :aria-label="site.lang" @mouseenter="showTooltip($event, site.lang)" @mouseleave="hideTooltip" /> 38 :aria-label="site.name"
39 @mouseenter="showTooltip($event, site.name)"
40 @mouseleave="hideTooltip"
41 ><span class="ext-site-name-inner">{{ site.name }}</span></span>
42 <span
43 v-if="site.rating !== 'safe'"
44 class="ext-site-nsfw"
45 :class="ratingIcon(site.rating)"
46 :aria-label="ratingTitle(site.rating)"
47 @mouseenter="showTooltip($event, ratingTitle(site.rating))"
48 @mouseleave="hideTooltip"
49 />
50 <span
51 class="ext-site-lang"
52 :class="langFlagClass(site.lang)"
53 :aria-label="site.lang"
54 @mouseenter="showTooltip($event, site.lang)"
55 @mouseleave="hideTooltip"
56 />
43 </div> 57 </div>
44 <span v-if="site.repoName" class="ext-site-repo">{{ site.repoName }}</span> 58 <span v-if="site.repoName" class="ext-site-repo">{{
59 site.repoName
60 }}</span>
45 </component> 61 </component>
46 <a v-if="site.installUrl" class="ext-site-install-btn" :href="site.installUrl" :aria-label="`Install ${site.name}`" @mouseenter="showTooltip($event, `Install ${site.name}`)" @mouseleave="hideTooltip"> 62 <a
63 v-if="site.installUrl"
64 class="ext-site-install-btn"
65 :href="site.installUrl"
66 :aria-label="`Install ${site.name}`"
67 @mouseenter="showTooltip($event, `Install ${site.name}`)"
68 @mouseleave="hideTooltip"
69 >
47 <span class="i-lucide:download" /> 70 <span class="i-lucide:download" />
48 </a> 71 </a>
49 <button v-if="site.installUrl && hasCopyButton(scheme ?? '')" class="ext-site-copy-btn" type="button" :aria-label="`Copy ${site.name} url`" @mouseenter="showTooltip($event, `Copy ${site.name} url`)" @mouseleave="hideTooltip" @click="copyInstallUrl"> 72 <button
50 <span v-if="copied" class="i-lucide:check" /> 73 v-if="site.installUrl && hasCopyButton(scheme ?? '')"
74 class="ext-site-copy-btn"
75 type="button"
76 :aria-label="`Copy ${site.name} url`"
77 @mouseenter="showTooltip($event, `Copy ${site.name} url`)"
78 @mouseleave="hideTooltip"
79 @click="copyInstallUrl"
80 >
81 <span v-if="copiedKey === site.installUrl" class="i-lucide:check" />
51 <span v-else class="i-lucide:copy" /> 82 <span v-else class="i-lucide:copy" />
52 </button> 83 </button>
53 </div> 84 </div>
54</template> 85</template>
55 86
87<style scoped src="./siteCellShared.css"></style>
88
56<style scoped> 89<style scoped>
57.ext-site-cell-wrap { 90.ext-site-cell-wrap {
58 display: flex; 91 display: flex;
@@ -60,97 +93,17 @@ async function copyInstallUrl() {
60 gap: 4px; 93 gap: 4px;
61 min-width: 0; 94 min-width: 0;
62} 95}
63
64.ext-site-repo {
65 display: block;
66 padding-left: 24px;
67 font-size: 10.5px;
68 font-weight: 400;
69 line-height: 1.1;
70 color: var(--vp-c-text-2);
71 white-space: nowrap;
72 overflow: hidden;
73 text-overflow: ellipsis;
74}
75
76.ext-site-cell {
77 flex: 1;
78 display: flex;
79 flex-direction: column;
80 gap: 0;
81 padding: 6px 8px;
82 border-radius: 6px;
83 border: 1px solid var(--vp-c-divider);
84 background-color: var(--vp-c-bg-soft);
85 min-width: 0;
86 color: var(--vp-c-text-1) !important;
87 text-decoration: none !important;
88 transition: border-color 0.2s, background-color 0.2s;
89}
90
91.ext-site-row {
92 display: flex;
93 align-items: center;
94 gap: 6px;
95 min-width: 0;
96}
97
98.ext-site-cell:hover { 96.ext-site-cell:hover {
99 border-color: var(--vp-c-brand-1); 97 border-color: var(--vp-c-brand-1);
100 background-color: var(--vp-c-bg); 98 background-color: var(--vp-c-bg);
101} 99}
102
103.ext-site-cell-static { 100.ext-site-cell-static {
104 cursor: default; 101 cursor: default;
105} 102}
106
107.ext-site-cell-static:hover { 103.ext-site-cell-static:hover {
108 border-color: var(--vp-c-divider); 104 border-color: var(--vp-c-divider);
109 background-color: var(--vp-c-bg-soft); 105 background-color: var(--vp-c-bg-soft);
110} 106}
111
112.ext-site-icon {
113 width: 18px;
114 height: 18px;
115 border-radius: 4px;
116 flex-shrink: 0;
117 object-fit: contain;
118}
119
120.ext-site-icon-fallback {
121 display: flex;
122 align-items: center;
123 justify-content: center;
124 color: var(--vp-c-text-3);
125}
126
127.ext-site-icon-loading {
128 background-color: var(--vp-c-bg-mute, var(--vp-c-bg-soft));
129}
130
131.ext-site-name-text {
132 display: block;
133 flex: 1;
134 min-width: 0;
135}
136
137.ext-site-name-inner {
138 display: block;
139 font-size: 12.5px;
140 font-weight: 600;
141 line-height: 1.2;
142 color: var(--vp-c-text-1);
143 white-space: nowrap;
144 overflow: hidden;
145 text-overflow: ellipsis;
146}
147
148.ext-site-nsfw,
149.ext-site-lang {
150 flex-shrink: 0;
151 font-size: 12px;
152}
153
154.ext-site-install-btn { 107.ext-site-install-btn {
155 flex-shrink: 0; 108 flex-shrink: 0;
156 display: flex; 109 display: flex;
@@ -164,16 +117,13 @@ async function copyInstallUrl() {
164 text-decoration: none !important; 117 text-decoration: none !important;
165 transition: filter 0.2s, border-color 0.2s; 118 transition: filter 0.2s, border-color 0.2s;
166} 119}
167
168.ext-site-install-btn:hover { 120.ext-site-install-btn:hover {
169 filter: brightness(1.08); 121 filter: brightness(1.08);
170 border-color: var(--vp-button-brand-hover-border); 122 border-color: var(--vp-button-brand-hover-border);
171} 123}
172
173.ext-site-install-btn span { 124.ext-site-install-btn span {
174 font-size: 15px; 125 font-size: 15px;
175} 126}
176
177.ext-site-copy-btn { 127.ext-site-copy-btn {
178 flex-shrink: 0; 128 flex-shrink: 0;
179 display: flex; 129 display: flex;
@@ -187,11 +137,9 @@ async function copyInstallUrl() {
187 cursor: pointer; 137 cursor: pointer;
188 transition: border-color 0.2s, background-color 0.2s; 138 transition: border-color 0.2s, background-color 0.2s;
189} 139}
190
191.ext-site-copy-btn:hover { 140.ext-site-copy-btn:hover {
192 border-color: var(--vp-c-brand-1); 141 border-color: var(--vp-c-brand-1);
193} 142}
194
195.ext-site-copy-btn span { 143.ext-site-copy-btn span {
196 font-size: 15px; 144 font-size: 15px;
197} 145}
docs/.vitepress/theme/components/extrepo/SiteGrid.vue +51 −23
@@ -1,5 +1,7 @@
1<script setup lang="ts"> 1<script setup lang="ts">
2import { computed, ref } from 'vue' 2import { computed, ref, watch } from 'vue'
3import { SITE_GRID_PAGE_SIZE } from './constants'
4import { groupSites } from './groupSites'
3import SiteCell from './SiteCell.vue' 5import SiteCell from './SiteCell.vue'
4import SiteGroupCell from './SiteGroupCell.vue' 6import SiteGroupCell from './SiteGroupCell.vue'
5import type { RepoSite } from './types' 7import type { RepoSite } from './types'
@@ -10,24 +12,7 @@ const props = defineProps<{
10 scheme?: string 12 scheme?: string
11}>() 13}>()
12 14
13interface SiteGroup { 15const groups = computed(() => groupSites(props.sites))
14 key: string
15 sites: (RepoSite & { repoName?: string })[]
16}
17
18const groups = computed<SiteGroup[]>(() => {
19 const map = new Map<string, SiteGroup>()
20 props.sites.forEach((site, i) => {
21 const key = site.url ? `${site.repoName ?? ''}-${site.url}` : `no-url-${i}`
22 let group = map.get(key)
23 if (!group) {
24 group = { key, sites: [] }
25 map.set(key, group)
26 }
27 group.sites.push(site)
28 })
29 return [...map.values()]
30})
31 16
32const openGroups = ref<Set<string>>(new Set()) 17const openGroups = ref<Set<string>>(new Set())
33 18
@@ -37,6 +22,20 @@ function toggleGroup(key: string) {
37 else next.add(key) 22 else next.add(key)
38 openGroups.value = next 23 openGroups.value = next
39} 24}
25
26const visibleCount = ref(SITE_GRID_PAGE_SIZE)
27watch(() => props.sites, () => {
28 visibleCount.value = SITE_GRID_PAGE_SIZE
29})
30
31const visibleGroups = computed(() => groups.value.slice(0, visibleCount.value))
32const remaining = computed(() =>
33 groups.value.length - visibleGroups.value.length
34)
35
36function showMore() {
37 visibleCount.value += SITE_GRID_PAGE_SIZE
38}
40</script> 39</script>
41 40
42<template> 41<template>
@@ -44,8 +43,12 @@ function toggleGroup(key: string) {
44 <div v-if="sites.length === 0" class="ext-site-empty"> 43 <div v-if="sites.length === 0" class="ext-site-empty">
45 {{ emptyText }} 44 {{ emptyText }}
46 </div> 45 </div>
47 <template v-for="group in groups" :key="group.key"> 46 <template v-for="group in visibleGroups" :key="group.key">
48 <SiteCell v-if="group.sites.length === 1" :site="group.sites[0]" :scheme="scheme" /> 47 <SiteCell
48 v-if="group.sites.length === 1"
49 :site="group.sites[0]"
50 :scheme="scheme"
51 />
49 <template v-else> 52 <template v-else>
50 <SiteGroupCell 53 <SiteGroupCell
51 :sites="group.sites" 54 :sites="group.sites"
@@ -53,10 +56,23 @@ function toggleGroup(key: string) {
53 @toggle="toggleGroup(group.key)" 56 @toggle="toggleGroup(group.key)"
54 /> 57 />
55 <template v-if="openGroups.has(group.key)"> 58 <template v-if="openGroups.has(group.key)">
56 <SiteCell v-for="site in group.sites" :key="`${group.key}-${site.lang}`" :site="site" :scheme="scheme" /> 59 <SiteCell
60 v-for="(site, j) in group.sites"
61 :key="`${group.key}::${site.lang}::${j}`"
62 :site="site"
63 :scheme="scheme"
64 />
57 </template> 65 </template>
58 </template> 66 </template>
59 </template> 67 </template>
68 <button
69 v-if="remaining > 0"
70 type="button"
71 class="ext-site-more"
72 @click="showMore"
73 >
74 Show more ({{ remaining }} remaining)
75 </button>
60 </div> 76 </div>
61</template> 77</template>
62 78
@@ -70,11 +86,23 @@ function toggleGroup(key: string) {
70 overflow-y: auto; 86 overflow-y: auto;
71 background-color: var(--vp-c-bg); 87 background-color: var(--vp-c-bg);
72} 88}
73
74.ext-site-empty { 89.ext-site-empty {
75 grid-column: 1 / -1; 90 grid-column: 1 / -1;
76 color: var(--vp-c-text-2); 91 color: var(--vp-c-text-2);
77 font-size: 13px; 92 font-size: 13px;
78 padding: 8px 4px; 93 padding: 8px 4px;
79} 94}
95.ext-site-more {
96 grid-column: 1 / -1;
97 padding: 8px;
98 border-radius: 8px;
99 border: 1px solid var(--vp-c-divider);
100 background-color: var(--vp-c-bg-soft);
101 color: var(--vp-c-text-1);
102 font-size: 13px;
103 cursor: pointer;
104}
105.ext-site-more:hover {
106 border-color: var(--vp-c-brand-1);
107}
80</style> 108</style>
docs/.vitepress/theme/components/extrepo/SiteGroupCell.vue +14 −82
@@ -17,8 +17,10 @@ defineEmits<{
17}>() 17}>()
18 18
19const primary = computed(() => props.sites[0]) 19const primary = computed(() => props.sites[0])
20const highestRated = computed(() => props.sites.find(site => site.rating === 'nsfw') 20const highestRated = computed(() =>
21 ?? props.sites.find(site => site.rating === 'suggestive')) 21 props.sites.find(site => site.rating === 'nsfw') ??
22 props.sites.find(site => site.rating === 'suggestive')
23)
22 24
23const groupName = computed(() => { 25const groupName = computed(() => {
24 const wordLists = props.sites.map(site => site.name.trim().split(/\s+/)) 26 const wordLists = props.sites.map(site => site.name.trim().split(/\s+/))
@@ -32,7 +34,10 @@ const groupName = computed(() => {
32 if (common.length > 0) return common.join(' ') 34 if (common.length > 0) return common.join(' ')
33 35
34 const label = langLabel(primary.value.lang) 36 const label = langLabel(primary.value.lang)
35 const stripped = primary.value.name.replace(new RegExp(`\\s*${label}$`, 'i'), '').trim() 37 const stripped = primary.value.name.replace(
38 new RegExp(`\\s*${label}$`, 'i'),
39 ''
40 ).trim()
36 return stripped || primary.value.name 41 return stripped || primary.value.name
37}) 42})
38</script> 43</script>
@@ -47,7 +52,7 @@ const groupName = computed(() => {
47 @click="$emit('toggle')" 52 @click="$emit('toggle')"
48 > 53 >
49 <div class="ext-site-row"> 54 <div class="ext-site-row">
50 <LazyIcon class="ext-site-icon" :src="primary.icon" :alt="primary.name" /> 55 <LazyIcon :src="primary.icon" :alt="primary.name" />
51 <span 56 <span
52 class="ext-site-name-text" 57 class="ext-site-name-text"
53 :aria-label="groupName" 58 :aria-label="groupName"
@@ -69,100 +74,27 @@ const groupName = computed(() => {
69 @mouseleave="hideTooltip" 74 @mouseleave="hideTooltip"
70 /> 75 />
71 </div> 76 </div>
72 <span v-if="primary.repoName" class="ext-site-repo">{{ primary.repoName }}</span> 77 <span v-if="primary.repoName" class="ext-site-repo">{{
78 primary.repoName
79 }}</span>
73 </button> 80 </button>
74</template> 81</template>
75 82
76<style scoped> 83<style scoped src="./siteCellShared.css"></style>
77.ext-site-cell {
78 display: flex;
79 flex-direction: column;
80 gap: 0;
81 padding: 6px 8px;
82 border-radius: 6px;
83 border: 1px solid var(--vp-c-divider);
84 background-color: var(--vp-c-bg-soft);
85 min-width: 0;
86 color: var(--vp-c-text-1) !important;
87 text-decoration: none !important;
88 transition: border-color 0.2s, background-color 0.2s;
89}
90 84
85<style scoped>
91.ext-site-group { 86.ext-site-group {
92 width: 100%; 87 width: 100%;
93 font: inherit; 88 font: inherit;
94 text-align: left; 89 text-align: left;
95 cursor: pointer; 90 cursor: pointer;
96} 91}
97
98.ext-site-group:hover, 92.ext-site-group:hover,
99.ext-site-group-active { 93.ext-site-group-active {
100 border-color: var(--vp-c-brand-1); 94 border-color: var(--vp-c-brand-1);
101 background-color: var(--vp-c-bg); 95 background-color: var(--vp-c-bg);
102} 96}
103
104.ext-site-row {
105 display: flex;
106 align-items: center;
107 gap: 6px;
108 min-width: 0;
109}
110
111.ext-site-icon {
112 width: 18px;
113 height: 18px;
114 border-radius: 4px;
115 flex-shrink: 0;
116 object-fit: contain;
117}
118
119.ext-site-icon-fallback {
120 display: flex;
121 align-items: center;
122 justify-content: center;
123 color: var(--vp-c-text-3);
124}
125
126.ext-site-icon-loading {
127 background-color: var(--vp-c-bg-mute, var(--vp-c-bg-soft));
128}
129
130.ext-site-name-text {
131 display: block;
132 flex: 1;
133 min-width: 0;
134}
135
136.ext-site-name-inner {
137 display: block;
138 font-size: 12.5px;
139 font-weight: 600;
140 line-height: 1.2;
141 color: var(--vp-c-text-1);
142 white-space: nowrap;
143 overflow: hidden;
144 text-overflow: ellipsis;
145}
146
147.ext-site-nsfw,
148.ext-site-layers {
149 flex-shrink: 0;
150 font-size: 12px;
151}
152
153.ext-site-layers { 97.ext-site-layers {
154 color: var(--vp-c-brand-1); 98 color: var(--vp-c-brand-1);
155} 99}
156
157.ext-site-repo {
158 display: block;
159 padding-left: 24px;
160 font-size: 10.5px;
161 font-weight: 400;
162 line-height: 1.1;
163 color: var(--vp-c-text-2);
164 white-space: nowrap;
165 overflow: hidden;
166 text-overflow: ellipsis;
167}
168</style> 100</style>
docs/.vitepress/theme/components/extrepo/constants.ts added +13
@@ -0,0 +1,13 @@
1export const SEARCH_DEBOUNCE_MS = 150
2export const SITE_GRID_PAGE_SIZE = 120
3export const ICON_ROOT_MARGIN = '200px'
4export const COPY_RESET_MS = 1500
5export const MAX_CONCURRENT_MOBILE = 6
6export const MAX_CONCURRENT_DESKTOP = 24
7export const STATUS_TICK_MS = 1500
8export const LOAD_TIMEOUT_MS = 30000
9export const CACHE_TTL_MS = 6 * 60 * 60 * 1000
10export const NOT_EXPANDABLE_REPOS = new Set([
11 'MegaRepo',
12 'Shotetsu Compatability'
13])
docs/.vitepress/theme/components/extrepo/groupSites.ts added +25
@@ -0,0 +1,25 @@
1import type { RepoSite } from './types'
2
3export interface SiteGroup {
4 key: string
5 sites: (RepoSite & { repoName?: string })[]
6}
7
8export function groupSites(
9 sites: (RepoSite & { repoName?: string })[]
10): SiteGroup[] {
11 const map = new Map<string, SiteGroup>()
12 for (const site of sites) {
13 const key = site.url
14 ? 'url::' + (site.repoName ?? '') + '::' + site.url
15 : 'nourl::' + site.name + '::' + site.lang + '::' +
16 (site.repoName ?? '') + '::' + site.icon
17 let group = map.get(key)
18 if (!group) {
19 group = { key, sites: [] }
20 map.set(key, group)
21 }
22 group.sites.push(site)
23 }
24 return [...map.values()]
25}
docs/.vitepress/theme/components/extrepo/helpers.ts +61 −16
@@ -1,33 +1,71 @@
1import { LANG_FLAG_FALLBACK, LANG_FLAG_ICONS } from '../../../configs/markdown/langFlags' 1import {
2 LANG_FLAG_FALLBACK,
3 LANG_FLAG_ICONS
4} from '../../../configs/markdown/langFlags'
2import type { Rating } from './types' 5import type { Rating } from './types'
3 6
4export function langFlagClass(lang: string): string { 7const flagCache = new Map<string, string>()
5 const key = lang.toLowerCase() 8const labelCache = new Map<string, string>()
6 const icon = LANG_FLAG_ICONS[key] ?? LANG_FLAG_ICONS[key.split('-')[0]] ?? LANG_FLAG_FALLBACK 9const stripCache = new Map<string, string>()
7 return `i-twemoji-${icon}` 10const contentTypeCache = new Map<string, string>()
8}
9 11
10const langDisplayNames = new Intl.DisplayNames(['en'], { type: 'language' }) 12const langDisplayNames = new Intl.DisplayNames(['en'], { type: 'language' })
11 13
12export function langLabel(lang: string): string { 14export function langFlagClass(lang: string = 'all'): string {
13 if (lang.toLowerCase() === 'all') return 'Multi-language' 15 const key = lang.toLowerCase()
14 try { 16 let hit = flagCache.get(key)
15 return langDisplayNames.of(lang) ?? lang 17 if (hit === undefined) {
16 } catch { 18 hit = `i-twemoji-${
17 return lang 19 LANG_FLAG_ICONS[key] ?? LANG_FLAG_ICONS[key.split('-')[0]] ??
20 LANG_FLAG_FALLBACK
21 }`
22 flagCache.set(key, hit)
18 } 23 }
24 return hit
25}
26
27export function langLabel(lang: string = 'all'): string {
28 const key = lang.toLowerCase()
29 let hit = labelCache.get(key)
30 if (hit === undefined) {
31 if (key === 'all') hit = 'Multi-language'
32 else {
33 try {
34 hit = langDisplayNames.of(lang) ?? lang
35 } catch {
36 hit = lang
37 }
38 }
39 labelCache.set(key, hit)
40 }
41 return hit
19} 42}
20 43
21export function stripHtml(html: string): string { 44export function stripHtml(html: string): string {
22 return html.replace(/<[^>]*>/g, '').trim() 45 let hit = stripCache.get(html)
46 if (hit === undefined) {
47 hit = html.replace(/<[^>]*>/g, '').trim()
48 if (stripCache.size > 2000) stripCache.clear()
49 stripCache.set(html, hit)
50 }
51 return hit
52}
53
54const ESCAPE_MAP: Record<string, string> = {
55 '&': '&amp;',
56 '<': '&lt;',
57 '>': '&gt;',
58 '"': '&quot;'
23} 59}
24 60
25export function escapeHtml(text: string): string { 61export function escapeHtml(text: string): string {
26 return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;') 62 return text.replace(/[&<>"]/g, c => ESCAPE_MAP[c])
27} 63}
28 64
29export function ratingIcon(rating: Rating): string { 65export function ratingIcon(rating: Rating): string {
30 return rating === 'nsfw' ? 'i-twemoji-no-one-under-eighteen' : 'i-twemoji-warning' 66 return rating === 'nsfw'
67 ? 'i-twemoji-no-one-under-eighteen'
68 : 'i-twemoji-warning'
31} 69}
32 70
33export function ratingTitle(rating: Rating): string { 71export function ratingTitle(rating: Rating): string {
@@ -35,5 +73,12 @@ export function ratingTitle(rating: Rating): string {
35} 73}
36 74
37export function contentTypeLabel(type: string): string { 75export function contentTypeLabel(type: string): string {
38 return type.toLowerCase().split('_').map(word => word.charAt(0).toUpperCase() + word.slice(1)).join(' ') 76 let hit = contentTypeCache.get(type)
77 if (hit === undefined) {
78 hit = type.toLowerCase().split('_').map(word =>
79 word.charAt(0).toUpperCase() + word.slice(1)
80 ).join(' ')
81 contentTypeCache.set(type, hit)
82 }
83 return hit
39} 84}
docs/.vitepress/theme/components/extrepo/iconObserver.ts added +41
@@ -0,0 +1,41 @@
1import { ICON_ROOT_MARGIN } from './constants'
2
3const callbacks = new Map<Element, () => void>()
4let observer: IntersectionObserver | undefined
5
6function ensureObserver(): IntersectionObserver | undefined {
7 if (
8 observer || typeof window === 'undefined' ||
9 !('IntersectionObserver' in window)
10 ) return observer
11 observer = new IntersectionObserver((entries) => {
12 for (const entry of entries) {
13 if (!entry.isIntersecting) continue
14 const cb = callbacks.get(entry.target)
15 if (cb) {
16 callbacks.delete(entry.target)
17 observer?.unobserve(entry.target)
18 cb()
19 }
20 }
21 }, { rootMargin: ICON_ROOT_MARGIN })
22 return observer
23}
24
25// Shared observer for all lazy icons; calls cb once when visible.
26export function observeIcon(el: Element, cb: () => void): () => void {
27 const io = ensureObserver()
28 if (!io) {
29 cb()
30 return () => {}
31 }
32 callbacks.set(el, cb)
33 io.observe(el)
34 return () => {
35 callbacks.delete(el)
36 io.unobserve(el)
37 }
38}
39
40// Remembers load results per src so repeated icons skip the queue.
41export const iconResultCache = new Map<string, boolean>()
docs/.vitepress/theme/components/extrepo/iconQueue.ts +17 −8
@@ -1,16 +1,20 @@
1const MAX_CONCURRENT_MOBILE = 6 1import { MAX_CONCURRENT_DESKTOP, MAX_CONCURRENT_MOBILE } from './constants'
2const MAX_CONCURRENT_DESKTOP = 24
3 2
4function maxConcurrent(): number { 3let limit = MAX_CONCURRENT_DESKTOP
5 if (typeof window === 'undefined') return MAX_CONCURRENT_DESKTOP 4if (typeof window !== 'undefined') {
6 return window.matchMedia('(max-width: 767px)').matches ? MAX_CONCURRENT_MOBILE : MAX_CONCURRENT_DESKTOP 5 const mq = window.matchMedia('(max-width: 767px)')
6 const sync = () => {
7 limit = mq.matches ? MAX_CONCURRENT_MOBILE : MAX_CONCURRENT_DESKTOP
8 }
9 sync()
10 mq.addEventListener('change', sync)
7} 11}
8 12
9let active = 0 13let active = 0
10const queue: (() => Promise<void>)[] = [] 14const queue: (() => Promise<void>)[] = []
11 15
12function pump() { 16function pump() {
13 while (active < maxConcurrent() && queue.length) { 17 while (active < limit && queue.length) {
14 const job = queue.shift()! 18 const job = queue.shift()!
15 active++ 19 active++
16 job().finally(() => { 20 job().finally(() => {
@@ -20,7 +24,12 @@ function pump() {
20 } 24 }
21} 25}
22 26
23export function scheduleIconLoad(load: () => Promise<void>) { 27// Returns a cancel fn that drops the job if it hasn't started yet.
24 queue.push(load) 28export function scheduleIconLoad(load: () => Promise<void>): () => void {
29 let cancelled = false
30 queue.push(() => cancelled ? Promise.resolve() : load())
25 pump() 31 pump()
32 return () => {
33 cancelled = true
34 }
26} 35}
docs/.vitepress/theme/components/extrepo/install.ts +42 −16
@@ -14,17 +14,24 @@ interface InstallOpts {
14 suwatteListUrl?: string 14 suwatteListUrl?: string
15} 15}
16 16
17const INSTALL_URL_BUILDERS: Record<string, (repo: Repo, opts?: InstallOpts) => string> = { 17const INSTALL_URL_BUILDERS: Record<
18 string,
19 (repo: Repo, opts?: InstallOpts) => string
20> = {
18 aidoku: repo => `aidoku://addSourceList?url=${repo.indexUrl}`, 21 aidoku: repo => `aidoku://addSourceList?url=${repo.indexUrl}`,
19 mihon: repo => `mihon://extension-store?url=${repo.indexUrl}`, 22 mihon: repo => `mihon://extension-store?url=${repo.indexUrl}`,
20 paperback: repo => `paperback://addRepo?displayName=${encodeURIComponent(stripHtml(repo.name))}&url=${paperbackBase(repo.indexUrl)}`, 23 paperback: repo =>
24 `paperback://addRepo?displayName=${
25 encodeURIComponent(stripHtml(repo.name))
26 }&url=${paperbackBase(repo.indexUrl)}`,
21 suwatte: (repo, opts) => { 27 suwatte: (repo, opts) => {
22 const listUrl = opts?.suwatteListUrl ?? suwatteBase(repo.indexUrl) 28 const listUrl = opts?.suwatteListUrl ?? suwatteBase(repo.indexUrl)
23 return opts?.suwatteV6 29 return opts?.suwatteV6
24 ? `suwatte://list?url=${listUrl}` 30 ? `suwatte://list?url=${listUrl}`
25 : `suwatte://AddSourceList?list=${encodeURIComponent(listUrl)}` 31 : `suwatte://AddSourceList?list=${encodeURIComponent(listUrl)}`
26 }, 32 },
27 cloudstreamrepo: repo => `cloudstreamrepo://${repo.indexUrl.replace(/^https?:\/\//, '')}`, 33 cloudstreamrepo: repo =>
34 `cloudstreamrepo://${repo.indexUrl.replace(/^https?:\/\//, '')}`,
28 hayase: repo => `hayase://extensions/install?url=${repo.indexUrl}`, 35 hayase: repo => `hayase://extensions/install?url=${repo.indexUrl}`,
29 legado: repo => `legado://import/bookSource?src=${repo.indexUrl}`, 36 legado: repo => `legado://import/bookSource?src=${repo.indexUrl}`,
30 lnreader: repo => `lnreader://repo/add?url=${repo.indexUrl}` 37 lnreader: repo => `lnreader://repo/add?url=${repo.indexUrl}`
@@ -34,12 +41,10 @@ const INSTALL_URL_BUILDERS: Record<string, (repo: Repo, opts?: InstallOpts) => s
34const MANUAL_ONLY_SCHEMES = new Set(['manual']) 41const MANUAL_ONLY_SCHEMES = new Set(['manual'])
35 42
36// Schemes with no install or copy action 43// Schemes with no install or copy action
37const BROWSE_ONLY_SCHEMES = new Set(['kotatsu', 'sora', 'echo']) 44const BROWSE_ONLY_SCHEMES = new Set(['kotatsu', 'echo'])
38 45
39const NO_COPY_SCHEMES = new Set(['suwatte', 'echo']) 46const NO_COPY_SCHEMES = new Set(['suwatte', 'echo'])
40 47
41const COPYABLE_BROWSE_ONLY_SCHEMES = new Set(['sora'])
42
43export function isBrowseOnly(scheme: string): boolean { 48export function isBrowseOnly(scheme: string): boolean {
44 return BROWSE_ONLY_SCHEMES.has(scheme) 49 return BROWSE_ONLY_SCHEMES.has(scheme)
45} 50}
@@ -48,14 +53,16 @@ export function hasCopyButton(scheme: string): boolean {
48 return !NO_COPY_SCHEMES.has(scheme) 53 return !NO_COPY_SCHEMES.has(scheme)
49} 54}
50 55
51export function hasBrowseOnlyCopyButton(scheme: string): boolean { 56export function installHref(
52 return COPYABLE_BROWSE_ONLY_SCHEMES.has(scheme) 57 scheme: string,
53} 58 repo: Repo,
54 59 opts?: InstallOpts
55export function installHref(scheme: string, repo: Repo, opts?: InstallOpts): string | null { 60): string | null {
56 const build = INSTALL_URL_BUILDERS[scheme] 61 const build = INSTALL_URL_BUILDERS[scheme]
57 if (build) return build(repo, opts) 62 if (build) return build(repo, opts)
58 if (MANUAL_ONLY_SCHEMES.has(scheme) || BROWSE_ONLY_SCHEMES.has(scheme)) return null 63 if (MANUAL_ONLY_SCHEMES.has(scheme) || BROWSE_ONLY_SCHEMES.has(scheme)) {
64 return null
65 }
59 return `${scheme}://add-repo?url=${repo.indexUrl}` 66 return `${scheme}://add-repo?url=${repo.indexUrl}`
60} 67}
61 68
@@ -67,7 +74,9 @@ export function copyValue(scheme: string, indexUrl: string): string {
67 74
68export function mangayomiHref(repo: Repo, variant: RepoVariant): string { 75export function mangayomiHref(repo: Repo, variant: RepoVariant): string {
69 const params: string[] = [] 76 const params: string[] = []
70 if (repo.repoName) params.push(`repo_name=${encodeURIComponent(repo.repoName)}`) 77 if (repo.repoName) {
78 params.push(`repo_name=${encodeURIComponent(repo.repoName)}`)
79 }
71 if (repo.repoUrl) params.push(`repo_url=${repo.repoUrl}`) 80 if (repo.repoUrl) params.push(`repo_url=${repo.repoUrl}`)
72 if (variant.mangaUrl) params.push(`manga_url=${variant.mangaUrl}`) 81 if (variant.mangaUrl) params.push(`manga_url=${variant.mangaUrl}`)
73 if (variant.animeUrl) params.push(`anime_url=${variant.animeUrl}`) 82 if (variant.animeUrl) params.push(`anime_url=${variant.animeUrl}`)
@@ -75,12 +84,29 @@ export function mangayomiHref(repo: Repo, variant: RepoVariant): string {
75 return `mangayomi://add-repo?${params.join('&')}` 84 return `mangayomi://add-repo?${params.join('&')}`
76} 85}
77 86
78export function mangayomiLiveContainerHref(repo: Repo, variant: RepoVariant): string { 87export function mangayomiLiveContainerHref(
79 return `livecontainer://open-url?url=${btoa(mangayomiHref(repo, variant))}` 88 repo: Repo,
89 variant: RepoVariant
90): string {
91 return `livecontainer://open-url?url=${
92 b64encodeUnicode(mangayomiHref(repo, variant))
93 }`
94}
95
96// btoa throws on non-latin1 chars, so encode UTF-8 first.
97function b64encodeUnicode(s: string): string {
98 const bytes = new TextEncoder().encode(s)
99 let bin = ''
100 for (let i = 0; i < bytes.length; i += 0x8000) {
101 bin += String.fromCharCode(...bytes.subarray(i, i + 0x8000))
102 }
103 return btoa(bin)
80} 104}
81 105
82// mangayomi all in one 106// mangayomi all in one
83export function mangayomiCopyValue(variant: RepoVariant): string | null { 107export function mangayomiCopyValue(variant: RepoVariant): string | null {
84 const urls = [variant.mangaUrl, variant.animeUrl, variant.novelUrl].filter(Boolean) 108 const urls = [variant.mangaUrl, variant.animeUrl, variant.novelUrl].filter(
109 Boolean
110 )
85 return urls.length === 1 ? urls[0]! : null 111 return urls.length === 1 ? urls[0]! : null
86} 112}
docs/.vitepress/theme/components/extrepo/repoRowShared.css added +71
@@ -0,0 +1,71 @@
1.ext-repo-actions {
2 display: flex;
3 align-items: center;
4 gap: 6px;
5 flex-shrink: 0;
6}
7.ext-btn {
8 display: inline-flex;
9 align-items: center;
10 gap: 4px;
11 padding: 5px 10px;
12 border-radius: 8px;
13 border: 1px solid var(--vp-c-divider);
14 background-color: var(--vp-c-bg);
15 color: var(--vp-c-text-1);
16 font-size: 13px;
17 line-height: 1;
18 cursor: pointer;
19 transition: border-color 0.2s, background-color 0.2s, color 0.2s;
20}
21.ext-btn:hover {
22 border-color: var(--vp-c-brand-1);
23}
24.ext-btn-install {
25 background-color: var(--vp-button-brand-bg);
26 color: var(--vp-button-brand-text) !important;
27 border-color: var(--vp-button-brand-border);
28 text-decoration: none !important;
29 font-weight: 600;
30}
31.ext-btn-install:hover {
32 filter: brightness(1.08);
33 border-color: var(--vp-button-brand-hover-border);
34}
35.ext-btn-copy,
36.ext-btn-livecontainer {
37 padding: 5px 8px;
38}
39.ext-btn-toggle {
40 padding: 0;
41 border: none;
42 background: transparent;
43 color: var(--vp-c-text-1);
44}
45.ext-btn-toggle:hover {
46 border-color: transparent;
47 color: var(--vp-c-brand-1);
48}
49.ext-btn-toggle span {
50 font-size: 18px;
51 transition: transform 0.2s;
52}
53.ext-btn-toggle.open span {
54 transform: rotate(180deg);
55}
56.ext-btn-toggle-hidden {
57 visibility: hidden;
58 pointer-events: none;
59}
60.ext-btn-spacer {
61 visibility: hidden;
62 pointer-events: none;
63}
64@media (max-width: 767px) {
65 .ext-btn-install {
66 padding: 5px 8px;
67 }
68 .ext-btn-install-label {
69 display: none;
70 }
71}
docs/.vitepress/theme/components/extrepo/siteCellShared.css added +52
@@ -0,0 +1,52 @@
1.ext-site-cell {
2 flex: 1;
3 display: flex;
4 flex-direction: column;
5 gap: 0;
6 padding: 6px 8px;
7 border-radius: 6px;
8 border: 1px solid var(--vp-c-divider);
9 background-color: var(--vp-c-bg-soft);
10 min-width: 0;
11 color: var(--vp-c-text-1) !important;
12 text-decoration: none !important;
13 transition: border-color 0.2s, background-color 0.2s;
14}
15.ext-site-row {
16 display: flex;
17 align-items: center;
18 gap: 6px;
19 min-width: 0;
20}
21.ext-site-name-text {
22 display: block;
23 flex: 1;
24 min-width: 0;
25}
26.ext-site-name-inner {
27 display: block;
28 font-size: 12.5px;
29 font-weight: 600;
30 line-height: 1.2;
31 color: var(--vp-c-text-1);
32 white-space: nowrap;
33 overflow: hidden;
34 text-overflow: ellipsis;
35}
36.ext-site-nsfw,
37.ext-site-lang,
38.ext-site-layers {
39 flex-shrink: 0;
40 font-size: 12px;
41}
42.ext-site-repo {
43 display: block;
44 padding-left: 24px;
45 font-size: 10.5px;
46 font-weight: 400;
47 line-height: 1.1;
48 color: var(--vp-c-text-2);
49 white-space: nowrap;
50 overflow: hidden;
51 text-overflow: ellipsis;
52}
docs/.vitepress/theme/components/extrepo/types.ts −2
@@ -25,8 +25,6 @@ export interface RepoSite {
25 url: string 25 url: string
26 rating: Rating 26 rating: Rating
27 contentType?: string 27 contentType?: string
28 streamType?: string
29 quality?: string
30 isBroken?: boolean 28 isBroken?: boolean
31 installUrl?: string 29 installUrl?: string
32} 30}
docs/.vitepress/theme/components/extrepo/useCopy.ts added +22
@@ -0,0 +1,22 @@
1import { onUnmounted, ref } from 'vue'
2import { COPY_RESET_MS } from './constants'
3
4export function useCopy() {
5 const copiedKey = ref<string | null>(null)
6 let timer: ReturnType<typeof setTimeout> | undefined
7
8 async function copy(key: string, value: string) {
9 await navigator.clipboard.writeText(value)
10 copiedKey.value = key
11 if (timer) clearTimeout(timer)
12 timer = setTimeout(() => {
13 if (copiedKey.value === key) copiedKey.value = null
14 }, COPY_RESET_MS)
15 }
16
17 onUnmounted(() => {
18 if (timer) clearTimeout(timer)
19 })
20
21 return { copiedKey, copy }
22}
docs/.vitepress/theme/components/extrepo/useDropdown.ts added +31
@@ -0,0 +1,31 @@
1import { onMounted, onUnmounted, ref } from 'vue'
2
3export function useDropdown() {
4 const rootRef = ref<HTMLElement>()
5 const open = ref(false)
6
7 function toggle() {
8 open.value = !open.value
9 }
10
11 function onDocClick(e: MouseEvent) {
12 if (rootRef.value && !rootRef.value.contains(e.target as Node)) {
13 open.value = false
14 }
15 }
16
17 function onKey(e: KeyboardEvent) {
18 if (e.key === 'Escape') open.value = false
19 }
20
21 onMounted(() => {
22 document.addEventListener('click', onDocClick, true)
23 document.addEventListener('keydown', onKey)
24 })
25 onUnmounted(() => {
26 document.removeEventListener('click', onDocClick, true)
27 document.removeEventListener('keydown', onKey)
28 })
29
30 return { rootRef, open, toggle }
31}
docs/.vitepress/theme/components/extrepo/useRepoFilter.ts added +80
@@ -0,0 +1,80 @@
1import { computed, type ComputedRef, type Ref } from 'vue'
2import { langLabel } from './helpers'
3import type { MatchedSite, RatingFilter } from './types'
4
5export interface RepoFilterState {
6 query: Ref<string>
7 langFilter: Ref<string>
8 ratingFilter: Ref<RatingFilter>
9 contentTypeFilter: Ref<string>
10 showBroken: Ref<boolean>
11}
12
13export interface IndexedSite extends MatchedSite {
14 hay: string
15}
16
17export function indexSites(sites: MatchedSite[]): IndexedSite[] {
18 return sites.map(site => ({
19 ...site,
20 hay: `${site.name ?? ''} ${site.url ?? ''}`.toLowerCase()
21 }))
22}
23
24export function useRepoFilter(
25 allSites: ComputedRef<IndexedSite[]>,
26 state: RepoFilterState
27) {
28 // Single pass over allSites for every facet + flag.
29 const facets = computed(() => {
30 const contentTypes = new Set<string>()
31 const langs = new Set<string>()
32 let hasRatings = false
33 let hasSuggestive = false
34 let hasMultiLanguage = false
35 let hasBroken = false
36 for (const site of allSites.value) {
37 if (site.contentType) contentTypes.add(site.contentType)
38 if (site.rating !== 'safe') hasRatings = true
39 if (site.rating === 'suggestive') hasSuggestive = true
40 if (site.isBroken) hasBroken = true
41 if (typeof site.lang !== 'string') continue
42 if (site.lang.toLowerCase() === 'all') hasMultiLanguage = true
43 if (site.lang !== 'all') langs.add(site.lang)
44 }
45 return {
46 availableContentTypes: [...contentTypes].sort(),
47 availableLangs: [...langs].sort((a, b) =>
48 langLabel(a).localeCompare(langLabel(b))
49 ),
50 hasRatings,
51 hasSuggestive,
52 hasMultiLanguage,
53 hasBroken
54 }
55 })
56
57 const isFiltering = computed(() => {
58 return state.query.value.trim() !== '' || state.langFilter.value !== '' ||
59 state.ratingFilter.value !== 'all' ||
60 state.contentTypeFilter.value !== ''
61 })
62
63 const filteredSites = computed(() => {
64 const q = state.query.value.trim().toLowerCase()
65 const lang = state.langFilter.value
66 const rating = state.ratingFilter.value
67 const ctype = state.contentTypeFilter.value
68 const showBroken = state.showBroken.value
69 return allSites.value.filter((site) => {
70 if (site.isBroken && !showBroken) return false
71 if (q && !site.hay.includes(q)) return false
72 if (lang && site.lang !== lang) return false
73 if (rating !== 'all' && site.rating !== rating) return false
74 if (ctype && site.contentType !== ctype) return false
75 return true
76 })
77 })
78
79 return { facets, isFiltering, filteredSites }
80}
docs/.vitepress/theme/components/extrepo/useRepoStore.ts added +153
@@ -0,0 +1,153 @@
1import {
2 inject,
3 type InjectionKey,
4 onMounted,
5 provide,
6 type ShallowRef,
7 shallowRef
8} from 'vue'
9import {
10 assembleSchemeData,
11 fetchJsonHttp
12} from '../../../../ext/extensionRepos/parsers'
13import type { ExtensionRepoData } from '../../../../ext/extensionRepos/shared'
14
15import { LOAD_TIMEOUT_MS } from './constants'
16
17export interface RepoStore {
18 store: ShallowRef<ExtensionRepoData | null>
19 loading: ShallowRef<boolean>
20 refreshing: ShallowRef<boolean>
21 refreshFailed: ShallowRef<boolean>
22 loadFailed: ShallowRef<boolean>
23 updatedAt: ShallowRef<number | null>
24 loadMs: ShallowRef<number | null>
25 refresh: () => Promise<void>
26 retry: () => Promise<void>
27}
28
29const KEY: InjectionKey<RepoStore> = Symbol('ext-store')
30
31const schemeModules = import.meta.glob<{ data: ExtensionRepoData }>(
32 '../../../../ext/extensionRepos/*.data.ts'
33)
34
35function emptyData(): ExtensionRepoData {
36 return { sites: {}, echoAuthors: {}, repoLists: {} }
37}
38
39// Never let a hung chunk or upstream fetch spin forever.
40function withTimeout<T>(p: Promise<T>, ms: number): Promise<T | null> {
41 let timer: ReturnType<typeof setTimeout> | undefined
42 const timeout = new Promise<null>((resolve) => {
43 timer = setTimeout(() => resolve(null), ms)
44 })
45 return Promise.race([p, timeout]).finally(() => {
46 if (timer) clearTimeout(timer)
47 })
48}
49
50async function loadSchemeData(scheme: string): Promise<ExtensionRepoData> {
51 const load = schemeModules[`../../../../ext/extensionRepos/${scheme}.data.ts`]
52 if (!load) return emptyData()
53 try {
54 const mod = await load()
55 return mod.data ?? emptyData()
56 } catch {
57 return emptyData()
58 }
59}
60
61export function provideRepoStore(scheme: string): RepoStore {
62 const store = shallowRef<ExtensionRepoData | null>(null)
63 const loading = shallowRef(false)
64 const refreshing = shallowRef(false)
65 const refreshFailed = shallowRef(false)
66 const loadFailed = shallowRef(false)
67 const updatedAt = shallowRef<number | null>(null)
68 const loadMs = shallowRef<number | null>(null)
69
70 async function loadInitial() {
71 if (loading.value) return
72 loading.value = true
73 loadFailed.value = false
74 const t0 = performance.now()
75 try {
76 const data = await withTimeout(loadSchemeData(scheme), LOAD_TIMEOUT_MS)
77 if (data === null) {
78 store.value = emptyData()
79 loadFailed.value = true
80 } else {
81 store.value = data
82 loadFailed.value = Object.keys(data.sites).length === 0
83 }
84 } catch {
85 store.value = emptyData()
86 loadFailed.value = true
87 } finally {
88 loadMs.value = Math.round(performance.now() - t0)
89 loading.value = false
90 }
91 }
92
93 async function refresh() {
94 const prev = store.value
95 if (!prev || refreshing.value) return
96 refreshing.value = true
97 refreshFailed.value = false
98 try {
99 const urls = Object.keys(prev.sites).filter(k => !k.includes('#'))
100 const fresh = await withTimeout(
101 assembleSchemeData(urls, Object.keys(prev.repoLists), fetchJsonHttp),
102 LOAD_TIMEOUT_MS
103 )
104 if (fresh === null) {
105 refreshFailed.value = true
106 return
107 }
108 if (Object.keys(fresh.sites).length === 0 && urls.length > 0) {
109 refreshFailed.value = true
110 return
111 }
112 const sites = { ...prev.sites }
113 for (const u of urls) {
114 if (u in fresh.sites) {
115 for (const k of Object.keys(sites)) {
116 if (k === u || k.startsWith(`${u}#`)) delete sites[k]
117 }
118 }
119 }
120 store.value = {
121 sites: { ...sites, ...fresh.sites },
122 echoAuthors: { ...prev.echoAuthors, ...fresh.echoAuthors },
123 repoLists: { ...prev.repoLists, ...fresh.repoLists }
124 }
125 updatedAt.value = Date.now()
126 } finally {
127 refreshing.value = false
128 }
129 }
130
131 onMounted(loadInitial)
132 const ctx: RepoStore = {
133 store,
134 loading,
135 refreshing,
136 refreshFailed,
137 loadFailed,
138 updatedAt,
139 loadMs,
140 refresh,
141 retry: loadInitial
142 }
143 provide(KEY, ctx)
144 return ctx
145}
146
147export function useRepoStore(): RepoStore {
148 const ctx = inject(KEY)
149 if (!ctx) {
150 throw new Error('useRepoStore() must be used within provideRepoStore()')
151 }
152 return ctx
153}
docs/.vitepress/theme/components/extrepo/useTooltip.ts +17 −3
@@ -1,4 +1,4 @@
1import { inject, provide, ref, type InjectionKey } from 'vue' 1import { inject, type InjectionKey, provide, ref } from 'vue'
2 2
3interface TooltipState { 3interface TooltipState {
4 text: string 4 text: string
@@ -13,11 +13,21 @@ interface TooltipCtx {
13 13
14const KEY: InjectionKey<TooltipCtx> = Symbol('ext-tooltip') 14const KEY: InjectionKey<TooltipCtx> = Symbol('ext-tooltip')
15 15
16let hoverable: boolean | undefined
17
18function canHover(): boolean {
19 if (hoverable === undefined) {
20 hoverable = typeof window !== 'undefined' &&
21 window.matchMedia('(hover: hover)').matches
22 }
23 return hoverable
24}
25
16export function provideTooltip() { 26export function provideTooltip() {
17 const tooltip = ref<TooltipState | null>(null) 27 const tooltip = ref<TooltipState | null>(null)
18 28
19 function show(e: MouseEvent, text: string) { 29 function show(e: MouseEvent, text: string) {
20 if (typeof window === 'undefined' || !window.matchMedia('(hover: hover)').matches) return 30 if (!canHover()) return
21 const rect = (e.currentTarget as HTMLElement).getBoundingClientRect() 31 const rect = (e.currentTarget as HTMLElement).getBoundingClientRect()
22 tooltip.value = { text, x: rect.left + rect.width / 2, y: rect.top } 32 tooltip.value = { text, x: rect.left + rect.width / 2, y: rect.top }
23 } 33 }
@@ -33,6 +43,10 @@ export function provideTooltip() {
33 43
34export function useTooltip(): TooltipCtx { 44export function useTooltip(): TooltipCtx {
35 const ctx = inject(KEY) 45 const ctx = inject(KEY)
36 if (!ctx) throw new Error('useTooltip() must be called within a component tree wrapped by provideTooltip()') 46 if (!ctx) {
47 throw new Error(
48 'useTooltip() must be called within a component tree wrapped by provideTooltip()'
49 )
50 }
37 return ctx 51 return ctx
38} 52}
docs/.vitepress/theme/globalComponents.ts +5 −1
@@ -1,8 +1,8 @@
1import type { App } from 'vue' 1import type { App } from 'vue'
2import { defineAsyncComponent } from 'vue'
2import Authors from './components/Authors.vue' 3import Authors from './components/Authors.vue'
3import Block from './components/Block.vue' 4import Block from './components/Block.vue'
4import Collapsible from './components/Collapsible.vue' 5import Collapsible from './components/Collapsible.vue'
5import { ExtensionRepos } from './components/extrepo'
6import Fb from './components/Fb.vue' 6import Fb from './components/Fb.vue'
7import Feedback from './components/Feedback.vue' 7import Feedback from './components/Feedback.vue'
8import Highlight from './components/Highlight.vue' 8import Highlight from './components/Highlight.vue'
@@ -11,6 +11,10 @@ import MirrorTooltip from './components/MirrorTooltip.vue'
11import ScrapeTable from './components/ScrapeTable.vue' 11import ScrapeTable from './components/ScrapeTable.vue'
12import Tooltip from './components/Tooltip.vue' 12import Tooltip from './components/Tooltip.vue'
13 13
14const ExtensionRepos = defineAsyncComponent(
15 () => import('./components/extrepo').then(m => m.ExtensionRepos)
16)
17
14export function registerGlobalComponents(app: App) { 18export function registerGlobalComponents(app: App) {
15 app.component('LinkInline', LinkInline) 19 app.component('LinkInline', LinkInline)
16 app.component('hl', Highlight) 20 app.component('hl', Highlight)
docs/ext/extensionRepos.data.ts deleted −979
@@ -1,979 +0,0 @@
1import { existsSync, mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'
2import { dirname, join } from 'node:path'
3import { fileURLToPath } from 'node:url'
4
5const IGNORED_DIRS = new Set(['node_modules', '.vitepress', '.git'])
6
7export type Rating = 'safe' | 'suggestive' | 'nsfw'
8
9export interface RepoSite {
10 name: string
11 lang: string
12 icon: string
13 url: string
14 rating: Rating
15 contentType?: string
16 streamType?: string
17 quality?: string
18 isBroken?: boolean
19 installUrl?: string
20}
21
22interface MihonIndexSource {
23 id: string
24 name: string
25 language: string
26 homeUrl: string
27 mirrorUrls?: string[]
28}
29
30interface MihonIndexExtension {
31 name: string
32 packageName: string
33 resources: {
34 apkUrl: string
35 iconUrl: string
36 jarUrl: string
37 }
38 extensionLib: string
39 versionCode: string
40 versionName: string
41 contentWarning: string
42 sources: MihonIndexSource[]
43}
44
45interface MihonIndex {
46 name: string
47 badgeLabel: string
48 signingKey: string
49 contact?: {
50 website?: string
51 discord?: string
52 }
53 extensionList: {
54 extensions: MihonIndexExtension[]
55 }
56}
57
58export interface RepoData {
59 sites: RepoSite[]
60 suwatteV6?: boolean
61 suwatteListUrl?: string
62}
63
64interface MihonSource {
65 name: string
66 lang: string
67 baseUrl: string
68}
69
70interface MihonExtension {
71 pkg: string
72 nsfw?: number
73 sources?: MihonSource[]
74}
75
76interface AidokuSource {
77 name: string
78 iconURL: string
79 languages?: string[]
80 contentRating?: number
81 baseURL: string
82}
83
84interface AidokuIndex {
85 sources: AidokuSource[]
86}
87
88interface AidokuLegacySource {
89 name: string
90 icon: string
91 lang: string
92 nsfw?: number
93}
94
95interface PaperbackSource {
96 id: string
97 name: string
98 icon: string
99 language?: string
100 contentRating?: string
101 websiteBaseURL?: string
102}
103
104interface PaperbackIndex {
105 sources: PaperbackSource[]
106 builtWith?: { toolchain?: string }
107}
108
109interface CloudstreamRepo {
110 name?: string
111 pluginLists: string[]
112}
113
114interface CloudstreamRepoListItem {
115 url: string
116 verified?: boolean
117}
118
119export interface RepoListEntry {
120 label: string
121 indexUrl: string
122 repoUrl?: string
123}
124
125interface CloudstreamPlugin {
126 name: string
127 iconUrl?: string
128 language?: string
129}
130
131interface HayaseExtension {
132 name: string
133 icon?: string
134 languages?: string[]
135}
136
137interface LegadoBookSource {
138 bookSourceName: string
139 bookSourceUrl: string
140 bookSourceGroup?: string
141}
142
143interface LNReaderPlugin {
144 name: string
145 lang: string
146 url: string
147 iconUrl?: string
148}
149
150interface MangayomiSource {
151 name: string
152 lang: string
153 baseUrl: string
154 iconUrl?: string
155 isNsfw?: boolean
156}
157
158interface IReaderSource {
159 pkg: string
160 apk: string
161 name: string
162 lang: string
163 nsfw?: boolean
164}
165
166interface SuwatteCatalogSource {
167 name: string
168 website?: string
169 languages?: string[]
170 thumbnail?: string
171 path?: string
172}
173
174interface SuwatteCatalogIndex {
175 listUrl?: string
176 catalogVersion?: number
177 sources: SuwatteCatalogSource[]
178}
179
180// For kotatsu
181interface KotatsuSite {
182 name: string
183 lang: string
184 url: string
185 icon: string
186 contentType: string
187 isBroken: boolean
188}
189
190interface KotatsuIndex {
191 sites: KotatsuSite[]
192}
193
194interface SoraRepoIndexEntry {
195 slug: string
196 name: string
197 source: string
198 path?: string
199 totalSources?: number
200 error?: string
201}
202
203interface SoraRepoIndex {
204 repos: SoraRepoIndexEntry[]
205}
206
207interface SoraModule {
208 sourceName: string
209 iconUrl?: string
210 iconURL?: string
211 language?: string
212 baseUrl?: string
213 scriptUrl?: string
214 scriptURL?: string
215 wotaku_sourceName?: string
216 wotaku_language?: string[]
217 wotaku_type?: string[]
218 wotaku_streamType?: string[]
219 wotaku_quality?: string[]
220}
221
222export interface SoraAuthorRepo {
223 label: string
224 repoUrl?: string
225 indexUrl: string
226}
227
228interface EchoExtension {
229 id: string
230 type: string
231 name: string
232 subtitle?: string
233 iconUrl?: string
234 url?: string
235 updateUrl: string
236}
237
238export interface EchoAuthorRepo {
239 label: string
240 repoUrl?: string
241 indexUrl: string
242}
243
244const EXT_DIR = dirname(fileURLToPath(import.meta.url))
245const DOCS_DIR = join(EXT_DIR, '..')
246const CACHE_DIR = join(EXT_DIR, '../.vitepress/cache/extension-repos')
247const CACHE_TTL_MS = 6 * 60 * 60 * 1000
248
249function findMarkdownFiles(dir: string): string[] {
250 const files: string[] = []
251 for (const entry of readdirSync(dir, { withFileTypes: true })) {
252 if (entry.isDirectory()) {
253 if (!IGNORED_DIRS.has(entry.name)) files.push(...findMarkdownFiles(join(dir, entry.name)))
254 } else if (entry.name.endsWith('.md')) {
255 files.push(join(dir, entry.name))
256 }
257 }
258 return files
259}
260
261function collectIndexUrls(): string[] {
262 const urls = new Set<string>()
263 const blockRe = /:::\s*extrepo[^\n]*\n([\s\S]*?)\n\s*:::/g
264 const rowRe = /^\s*-\s*(raw|manga|anime|novel|data)\s*:\s*(https?:\/\/\S+)\s*$/i
265 const headingRe = /^\s*==\s+.+$/
266 const buildRe = /^\s*--\s+.+$/
267
268 function flushEntry(plainRaws: string[], variantUrls: string[], buildRaws: string[], dataUrls: string[]): void {
269 for (const url of variantUrls) urls.add(url)
270 for (const url of buildRaws) urls.add(url)
271 for (const url of dataUrls) urls.add(url)
272 if (dataUrls.length === 0) {
273 for (const url of plainRaws) urls.add(url)
274 }
275 }
276
277 for (const file of findMarkdownFiles(DOCS_DIR)) {
278 const src = readFileSync(file, 'utf-8')
279
280 let block: RegExpExecArray | null
281 blockRe.lastIndex = 0
282 while ((block = blockRe.exec(src))) {
283 let plainRaws: string[] = []
284 let variantUrls: string[] = []
285 let buildRaws: string[] = []
286 let dataUrls: string[] = []
287 let inEntry = false
288 let inBuild = false
289
290 for (const line of block[1].split('\n')) {
291 if (headingRe.test(line)) {
292 if (inEntry) flushEntry(plainRaws, variantUrls, buildRaws, dataUrls)
293 plainRaws = []
294 variantUrls = []
295 buildRaws = []
296 dataUrls = []
297 inEntry = true
298 inBuild = false
299 continue
300 }
301 if (buildRe.test(line)) {
302 inBuild = true
303 continue
304 }
305 const row = rowRe.exec(line)
306 if (row && inEntry) {
307 const key = row[1].toLowerCase()
308 const url = row[2].trim()
309 if (key === 'data') dataUrls.push(url)
310 else if (key === 'raw') (inBuild ? buildRaws : plainRaws).push(url)
311 else variantUrls.push(url)
312 }
313 }
314 if (inEntry) flushEntry(plainRaws, variantUrls, buildRaws, dataUrls)
315 }
316 }
317 return [...urls]
318}
319
320function cachePathFor(url: string): string {
321 return join(CACHE_DIR, `${Buffer.from(url).toString('base64url')}.json`)
322}
323
324function collectRepoListUrls(): string[] {
325 const urls = new Set<string>()
326 const blockRe = /:::\s*extrepo\s*\{([^}]*)\}/g
327
328 for (const file of findMarkdownFiles(DOCS_DIR)) {
329 const src = readFileSync(file, 'utf-8')
330
331 let match: RegExpExecArray | null
332 blockRe.lastIndex = 0
333 while ((match = blockRe.exec(src))) {
334 const from = match[1].match(/(?:^|\s)from=(?:"([^"]+)"|'([^']+)'|(\S+))/)
335 if (from) urls.add((from[1] ?? from[2] ?? from[3]).trim())
336 }
337 }
338 return [...urls]
339}
340
341function isCloudstreamRepoList(json: unknown): json is Array<string | CloudstreamRepoListItem> {
342 if (!Array.isArray(json) || json.length === 0) return false
343 return json.every(item => {
344 if (typeof item === 'string') return /^https?:\/\//.test(item)
345 if (item && typeof item === 'object') {
346 const rec = item as Record<string, unknown>
347 // LNReader plugins also carry a `url` field — rule those out.
348 if ('name' in rec || 'lang' in rec || 'baseUrl' in rec || 'baseURL' in rec) return false
349 return typeof rec.url === 'string' && /^https?:\/\//.test(rec.url)
350 }
351 return false
352 })
353}
354
355function inferRepoUrl(rawUrl: string): string | undefined {
356 try {
357 const u = new URL(rawUrl)
358 const parts = u.pathname.split('/').filter(Boolean)
359 if (u.hostname === 'raw.githubusercontent.com' && parts.length >= 2) {
360 return `https://github.com/${parts[0]}/${parts[1]}`
361 }
362 const dashRaw = u.pathname.indexOf('/-/raw/')
363 if (dashRaw > 0) return `${u.origin}${u.pathname.slice(0, dashRaw)}`
364 const rawSeg = parts.indexOf('raw')
365 if (rawSeg > 1) return `${u.origin}/${parts.slice(0, rawSeg).join('/')}`
366 } catch {
367 return undefined
368 }
369 return undefined
370}
371
372function inferLabel(rawUrl: string): string {
373 const repoUrl = inferRepoUrl(rawUrl)
374 if (repoUrl) {
375 try {
376 const parts = new URL(repoUrl).pathname.split('/').filter(Boolean)
377 if (parts.length >= 2) return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`
378 if (parts.length === 1) return decodeURIComponent(parts[0])
379 } catch {
380 // fall through to raw-URL fallback below
381 }
382 }
383 try {
384 const parts = new URL(rawUrl).pathname.split('/').filter(Boolean)
385 return decodeURIComponent(parts[parts.length - 2] ?? parts[parts.length - 1] ?? rawUrl)
386 } catch {
387 return rawUrl
388 }
389}
390
391function repoListLabel(indexUrl: string, repoJson: unknown): string {
392 if (repoJson && typeof repoJson === 'object' && !Array.isArray(repoJson)) {
393 const name = (repoJson as { name?: unknown }).name
394 if (typeof name === 'string' && name.trim() !== '') return name.trim()
395 }
396 return inferLabel(indexUrl)
397}
398
399async function fetchIndex(url: string): Promise<unknown> {
400 const cachePath = cachePathFor(url)
401 if (existsSync(cachePath) && Date.now() - statSync(cachePath).mtimeMs < CACHE_TTL_MS) {
402 return JSON.parse(readFileSync(cachePath, 'utf-8'))
403 }
404
405 try {
406 const res = await fetch(url)
407 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
408 const json = await res.json()
409 mkdirSync(CACHE_DIR, { recursive: true })
410 writeFileSync(cachePath, JSON.stringify(json))
411 return json
412 } catch (err) {
413 if (existsSync(cachePath)) return JSON.parse(readFileSync(cachePath, 'utf-8'))
414 console.warn(`[extrepo] failed to fetch ${url}: ${(err as Error).message}`)
415 return []
416 }
417}
418
419function ratingFromLevel(level: number): Rating {
420 if (level >= 2) return 'nsfw'
421 if (level >= 1) return 'suggestive'
422 return 'safe'
423}
424
425const LANG_ALIASES: Record<string, string> = {
426 jp: 'ja',
427 english: 'en',
428 'bahasa indonesia': 'id',
429 español: 'es',
430 français: 'fr',
431 polski: 'pl',
432 português: 'pt',
433 'tiếng việt': 'vi',
434 türkçe: 'tr',
435 русский: 'ru',
436 українська: 'uk',
437 ไทย: 'th',
438 العربية: 'ar',
439 chinese: 'zh',
440 japanese: 'ja',
441 korean: 'ko',
442 french: 'fr',
443 german: 'de',
444 greek: 'el',
445 indonesian: 'id',
446 italian: 'it',
447 spanish: 'es',
448 turkish: 'tr',
449 polish: 'pl',
450 russian: 'ru',
451 portuguese: 'pt',
452 arabic: 'ar',
453 tamil: 'ta',
454 ukrainian: 'uk',
455 vietnamese: 'vi',
456 thai: 'th',
457 hindi: 'hi',
458 malay: 'ms',
459 serbian: 'sr'
460}
461
462const LANG_SUBSTRING_ALIASES: [RegExp, string][] = [
463 [/日语原版/, 'ja'],
464 [/中文|汉语|漢語|轻小说/, 'zh'],
465 [/日本語/, 'ja'],
466 [/한국어|조선말/, 'ko']
467]
468
469function normalizeLang(lang: string): string {
470 // Strip bidi control marks (e.g. U+200E/U+200F) some indices prepend to lang names.
471 const cleaned = lang.replace(/[‎‏]/g, '').trim()
472 if (cleaned === '') return 'all'
473 const exact = LANG_ALIASES[cleaned.toLowerCase()]
474 if (exact) return exact
475 for (const [re, code] of LANG_SUBSTRING_ALIASES) {
476 if (re.test(cleaned)) return code
477 }
478 const key = cleaned.toLowerCase()
479 return key === 'multi' ? 'all' : key
480}
481
482function toRepoDataMihon(iconBase: string, extensions: MihonExtension[]): RepoSite[] {
483 const seen = new Set<string>()
484 const sites: RepoSite[] = []
485
486 for (const ext of extensions) {
487 const icon = `${iconBase}/icon/${ext.pkg}.png`
488 for (const source of ext.sources ?? []) {
489 const key = `${source.name}::${source.lang}::${source.baseUrl}`
490 if (seen.has(key)) continue
491 seen.add(key)
492 sites.push({ name: source.name, lang: source.lang, icon, url: source.baseUrl, rating: ext.nsfw === 1 ? 'nsfw' : 'safe' })
493 }
494 }
495
496 return sites
497}
498
499function toRepoDataAidoku(iconBase: string, index: AidokuIndex): RepoSite[] {
500 const seen = new Set<string>()
501 const sites: RepoSite[] = []
502
503 for (const source of index.sources ?? []) {
504 const icon = `${iconBase}/${source.iconURL}`
505 const rating = ratingFromLevel(source.contentRating ?? 0)
506 const langs = source.languages?.length ? source.languages : ['all']
507 for (const rawLang of langs) {
508 const lang = normalizeLang(rawLang)
509 const key = `${source.name}::${lang}::${source.baseURL}`
510 if (seen.has(key)) continue
511 seen.add(key)
512 sites.push({ name: source.name, lang, icon, url: source.baseURL, rating })
513 }
514 }
515
516 return sites
517}
518
519function toRepoDataPaperback(iconBase: string, index: PaperbackIndex): RepoSite[] {
520 const seen = new Set<string>()
521 const sites: RepoSite[] = []
522 // Legacy 0.8.x toolchain builds serve icons under `<id>/includes/`
523 const iconDir = index.builtWith?.toolchain?.startsWith('0.8') ? 'includes' : 'static'
524
525 for (const source of index.sources ?? []) {
526 const lang = normalizeLang(source.language ?? 'all')
527 const key = `${source.id}::${lang}`
528 if (seen.has(key)) continue
529 seen.add(key)
530 const icon = `${iconBase}/${source.id}/${iconDir}/${source.icon}`
531 const rating: Rating = source.contentRating === 'ADULT' ? 'nsfw' : source.contentRating === 'MATURE' ? 'suggestive' : 'safe'
532 sites.push({ name: source.name, lang, icon, url: source.websiteBaseURL ?? '', rating })
533 }
534
535 return sites
536}
537
538function normalizeGoogleFaviconUrl(url: string): string {
539 return url.replace('%size%', '64')
540}
541
542async function toRepoDataCloudstream(repo: CloudstreamRepo): Promise<RepoSite[]> {
543 const seen = new Set<string>()
544 const sites: RepoSite[] = []
545
546 const lists = await Promise.all(repo.pluginLists.map(url => fetchIndex(url)))
547 for (const list of lists) {
548 if (!Array.isArray(list)) continue
549 for (const plugin of list as CloudstreamPlugin[]) {
550 if (seen.has(plugin.name)) continue
551 seen.add(plugin.name)
552 const lang = normalizeLang(plugin.language ?? 'all')
553 const icon = plugin.iconUrl ? normalizeGoogleFaviconUrl(plugin.iconUrl) : ''
554 sites.push({ name: plugin.name, lang, icon, url: '', rating: 'safe' })
555 }
556 }
557
558 return sites
559}
560
561function toRepoDataAidokuLegacy(iconBase: string, sources: AidokuLegacySource[]): RepoSite[] {
562 const seen = new Set<string>()
563 const sites: RepoSite[] = []
564
565 for (const source of sources) {
566 const lang = normalizeLang(source.lang)
567 const key = `${source.name}::${lang}`
568 if (seen.has(key)) continue
569 seen.add(key)
570 sites.push({ name: source.name, lang, icon: `${iconBase}/icons/${source.icon}`, url: '', rating: ratingFromLevel(source.nsfw ?? 0) })
571 }
572
573 return sites
574}
575
576function toRepoDataHayase(extensions: HayaseExtension[]): RepoSite[] {
577 const seen = new Set<string>()
578 const sites: RepoSite[] = []
579
580 for (const ext of extensions) {
581 const langs = ext.languages?.length ? ext.languages : ['all']
582 for (const rawLang of langs) {
583 const lang = normalizeLang(rawLang)
584 const key = `${ext.name}::${lang}`
585 if (seen.has(key)) continue
586 seen.add(key)
587 sites.push({ name: ext.name, lang, icon: ext.icon ?? '', url: '', rating: 'safe' })
588 }
589 }
590
591 return sites
592}
593
594function toRepoDataLegado(sources: LegadoBookSource[]): RepoSite[] {
595 const seen = new Set<string>()
596 const sites: RepoSite[] = []
597
598 for (const source of sources) {
599 const lang = normalizeLang(source.bookSourceGroup ?? 'all')
600 const key = `${source.bookSourceName}::${lang}`
601 if (seen.has(key)) continue
602 seen.add(key)
603 sites.push({ name: source.bookSourceName, lang, icon: '', url: source.bookSourceUrl, rating: 'safe' })
604 }
605
606 return sites
607}
608
609function toRepoDataMangayomi(sources: MangayomiSource[]): RepoSite[] {
610 const seen = new Set<string>()
611 const sites: RepoSite[] = []
612
613 for (const source of sources) {
614 const lang = normalizeLang(source.lang)
615 const key = `${source.name}::${lang}`
616 if (seen.has(key)) continue
617 seen.add(key)
618 sites.push({ name: source.name, lang, icon: source.iconUrl ?? '', url: source.baseUrl, rating: source.isNsfw ? 'nsfw' : 'safe' })
619 }
620
621 return sites
622}
623
624function toRepoDataIReader(sources: IReaderSource[]): RepoSite[] {
625 const seen = new Set<string>()
626 const sites: RepoSite[] = []
627
628 for (const source of sources) {
629 const lang = normalizeLang(source.lang)
630 const key = `${source.name}::${lang}`
631 if (seen.has(key)) continue
632 seen.add(key)
633 // No confirmed icon path convention in this repo's format — omit rather than guess wrong.
634 sites.push({ name: source.name, lang, icon: '', url: '', rating: source.nsfw ? 'nsfw' : 'safe' })
635 }
636
637 return sites
638}
639
640function toRepoDataSuwatte(iconBase: string, index: SuwatteCatalogIndex): { sites: RepoSite[]; listUrl: string } {
641 const seen = new Set<string>()
642 const sites: RepoSite[] = []
643
644 const listUrl = index.listUrl ?? iconBase
645 const isV6 = index.catalogVersion === undefined
646
647 for (const source of index.sources ?? []) {
648 const langs = source.languages?.length ? source.languages : ['all']
649 const icon = source.thumbnail
650 ? (/^https?:\/\//i.test(source.thumbnail) ? source.thumbnail : `${iconBase}/assets/${source.thumbnail}`)
651 : ''
652 const installUrl = source.path
653 ? (isV6
654 ? `suwatte://runner?url=${listUrl}&runner=${source.path}`
655 : `suwatte://AddSourceFromList?list=${listUrl}&source=${source.path}`)
656 : undefined
657 for (const rawLang of langs) {
658 const lang = normalizeLang(rawLang)
659 const key = `${source.name}::${lang}`
660 if (seen.has(key)) continue
661 seen.add(key)
662 sites.push({ name: source.name, lang, icon, url: source.website ?? '', rating: 'safe', installUrl })
663 }
664 }
665
666 return { sites, listUrl }
667}
668
669function toRepoDataKotatsu(index: KotatsuIndex): RepoSite[] {
670 const seen = new Set<string>()
671 const sites: RepoSite[] = []
672
673 for (const site of index.sites) {
674 const lang = normalizeLang(site.lang)
675 const key = `${site.name}::${lang}::${site.url}`
676 if (seen.has(key)) continue
677 seen.add(key)
678 const rating: Rating = site.contentType.includes('HENTAI') ? 'nsfw' : 'safe'
679 sites.push({ name: site.name, lang, icon: site.icon, url: site.url, rating, contentType: site.contentType, isBroken: site.isBroken || undefined })
680 }
681
682 return sites
683}
684
685function isSoraRepoIndex(json: unknown): json is SoraRepoIndex {
686 return !!json && typeof json === 'object' && Array.isArray((json as SoraRepoIndex).repos)
687}
688
689function normalizeSoraLang(language: string | undefined): string {
690 const stripped = (language ?? '').replace(/\s*\([^)]*\)\s*$/, '').trim()
691 if (stripped.toLowerCase().startsWith('multi')) return 'all'
692 return normalizeLang(stripped)
693}
694
695function toRepoDataSoraModules(modules: SoraModule[]): RepoSite[] {
696 const seen = new Set<string>()
697 const sites: RepoSite[] = []
698
699 for (const mod of modules) {
700 const name = mod.wotaku_sourceName ?? mod.sourceName
701 const langs = mod.wotaku_language?.length ? mod.wotaku_language : [mod.language]
702 const scriptUrl = mod.scriptUrl ?? mod.scriptURL
703 const installUrl = scriptUrl?.replace(/\.js$/i, '.json')
704 for (const rawLang of langs) {
705 const lang = normalizeSoraLang(rawLang)
706 const key = `${name}::${lang}::${installUrl ?? ''}`
707 if (seen.has(key)) continue
708 seen.add(key)
709 sites.push({
710 name,
711 lang,
712 icon: mod.iconUrl ?? mod.iconURL ?? '',
713 url: mod.baseUrl ?? '',
714 rating: 'safe',
715 contentType: mod.wotaku_type?.[0],
716 streamType: mod.wotaku_streamType?.[0],
717 quality: mod.wotaku_quality?.[0],
718 installUrl: installUrl ? `sora://module?url=${installUrl}` : undefined
719 })
720 }
721 }
722
723 sites.sort((a, b) => a.name.localeCompare(b.name))
724 return sites
725}
726
727async function loadSoraRepoIndex(indexUrl: string, index: SoraRepoIndex): Promise<{ sites: RepoSite[]; authorRepos: SoraAuthorRepo[]; sitesByAuthor: Record<string, RepoData> }> {
728 const seen = new Set<string>()
729 const sites: RepoSite[] = []
730 const authorRepos: SoraAuthorRepo[] = []
731 const sitesByAuthor: Record<string, RepoData> = {}
732
733 const entries = index.repos.filter(repo => repo.path && !repo.error)
734 const fileUrls = entries.map(repo => new URL(repo.path!, indexUrl).toString())
735 const moduleLists = await Promise.all(fileUrls.map(url => fetchIndex(url)))
736
737 entries.forEach((repo, i) => {
738 const modules = moduleLists[i]
739 const authorSites = Array.isArray(modules) ? toRepoDataSoraModules(modules as SoraModule[]) : []
740 const fileUrl = fileUrls[i]
741 sitesByAuthor[fileUrl] = { sites: authorSites }
742 authorRepos.push({ label: repo.name, repoUrl: repo.source?.replace(/\.git$/, ''), indexUrl: fileUrl })
743 for (const site of authorSites) {
744 const key = `${site.name}::${site.lang}::${site.installUrl ?? ''}`
745 if (seen.has(key)) continue
746 seen.add(key)
747 sites.push(site)
748 }
749 })
750
751 authorRepos.sort((a, b) => a.label.localeCompare(b.label))
752 sites.sort((a, b) => a.name.localeCompare(b.name))
753 return { sites, authorRepos, sitesByAuthor }
754}
755
756function isEchoExtensionList(json: unknown): json is EchoExtension[] {
757 if (!Array.isArray(json) || json.length === 0) return false
758 const first = json[0] as Record<string, unknown>
759 return typeof first.updateUrl === 'string' && typeof first.subtitle === 'string' && !('lang' in first) && !('baseUrl' in first)
760}
761
762function parseEchoRepo(updateUrl: string): { host: string; owner: string; repo: string; repoUrl: string; ownerUrl: string } | undefined {
763 const githubMatch = updateUrl.match(/^https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/releases$/)
764 if (githubMatch) {
765 const [, owner, repo] = githubMatch
766 return { host: 'github.com', owner, repo, repoUrl: `https://github.com/${owner}/${repo}`, ownerUrl: `https://github.com/${owner}` }
767 }
768
769 const gitlabMatch = updateUrl.match(/^https:\/\/(gitlab\.com)\/api\/v4\/projects\/([^/]+)\/releases\b/)
770 if (gitlabMatch) {
771 const [, host, encodedPath] = gitlabMatch
772 const path = decodeURIComponent(encodedPath)
773 const owner = path.slice(0, path.lastIndexOf('/'))
774 const repo = path.slice(path.lastIndexOf('/') + 1)
775 if (!owner || !repo) return undefined
776 return { host, owner, repo, repoUrl: `https://${host}/${path}`, ownerUrl: `https://${host}/${owner}` }
777 }
778
779 return undefined
780}
781
782function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] {
783 const seen = new Set<string>()
784 const sites: RepoSite[] = []
785
786 for (const ext of extensions) {
787 const key = `${ext.id}::${ext.updateUrl}`
788 if (seen.has(key)) continue
789 seen.add(key)
790 const repo = parseEchoRepo(ext.updateUrl)
791 sites.push({
792 name: ext.name,
793 lang: 'all',
794 icon: ext.iconUrl ?? '',
795 url: ext.url ?? repo?.repoUrl ?? '',
796 rating: 'safe',
797 contentType: ext.type,
798 installUrl: repo?.repoUrl
799 })
800 }
801
802 sites.sort((a, b) => a.name.localeCompare(b.name))
803 return sites
804}
805
806function loadEchoExtensionList(indexUrl: string, extensions: EchoExtension[]): { sites: RepoSite[]; authorRepos: EchoAuthorRepo[]; sitesByAuthor: Record<string, RepoData> } {
807 const byAuthor = new Map<string, { label: string; ownerUrl?: string; exts: EchoExtension[] }>()
808 for (const ext of extensions) {
809 const repo = parseEchoRepo(ext.updateUrl)
810 const key = repo ? `${repo.host}:${repo.owner}` : 'Unknown'
811 const bucket = byAuthor.get(key)
812 if (bucket) bucket.exts.push(ext)
813 else byAuthor.set(key, { label: repo?.owner ?? 'Unknown', ownerUrl: repo?.ownerUrl, exts: [ext] })
814 }
815
816 const authorRepos: EchoAuthorRepo[] = []
817 const sitesByAuthor: Record<string, RepoData> = {}
818 for (const [key, { label, ownerUrl, exts }] of byAuthor) {
819 const authorIndexUrl = `${indexUrl}#${key}`
820 sitesByAuthor[authorIndexUrl] = { sites: toRepoDataEchoExtensions(exts) }
821 authorRepos.push({ label, repoUrl: ownerUrl, indexUrl: authorIndexUrl })
822 }
823
824 authorRepos.sort((a, b) => a.label.localeCompare(b.label))
825 return { sites: toRepoDataEchoExtensions(extensions), authorRepos, sitesByAuthor }
826}
827
828function toRepoDataLNReader(plugins: LNReaderPlugin[]): RepoSite[] {
829 const seen = new Set<string>()
830 const sites: RepoSite[] = []
831
832 for (const plugin of plugins) {
833 const lang = normalizeLang(plugin.lang)
834 const key = `${plugin.name}::${lang}`
835 if (seen.has(key)) continue
836 seen.add(key)
837 sites.push({ name: plugin.name, lang, icon: plugin.iconUrl ?? '', url: plugin.url, rating: 'safe' })
838 }
839
840 return sites
841}
842
843const CONTENT_WARNING_RATING: Record<string, Rating> = {
844 CONTENT_WARNING_NSFW: 'nsfw',
845 CONTENT_WARNING_MIXED: 'suggestive',
846 CONTENT_WARNING_SAFE: 'safe'
847}
848
849function toRepoDataMihonNew(index: MihonIndex): RepoSite[] {
850 const seen = new Set<string>()
851 const sites: RepoSite[] = []
852
853 for (const ext of index.extensionList.extensions) {
854 const icon = ext.resources.iconUrl
855 const rating = CONTENT_WARNING_RATING[ext.contentWarning] ?? 'safe'
856
857 for (const source of ext.sources) {
858 const key = `${source.name}::${source.language}::${source.homeUrl}`
859 if (seen.has(key)) continue
860 seen.add(key)
861 sites.push({ name: source.name, lang: source.language, icon, url: source.homeUrl, rating })
862 }
863 }
864
865 sites.sort((a, b) => a.name.localeCompare(b.name))
866 return sites
867}
868
869async function toRepoData(indexUrl: string, json: unknown): Promise<RepoData> {
870 const iconBase = indexUrl.slice(0, indexUrl.lastIndexOf('/'))
871 let sites: RepoSite[]
872 let suwatteV6: boolean | undefined
873 let suwatteListUrl: string | undefined
874
875 if (
876 json && typeof json === 'object' && !Array.isArray(json)
877 && 'extensionList' in (json as Record<string, unknown>)
878 ) {
879 sites = toRepoDataMihonNew(json as MihonIndex)
880 return { sites }
881 }
882
883 if (Array.isArray(json)) {
884 const first = json[0] as Record<string, unknown> | undefined
885 if (first && 'bookSourceUrl' in first) {
886 sites = toRepoDataLegado(json as LegadoBookSource[])
887 } else if (first && 'manifestVersion' in first) {
888 sites = toRepoDataHayase(json as HayaseExtension[])
889 } else if (first && 'iconUrl' in first && 'site' in first) {
890 sites = toRepoDataLNReader(json as LNReaderPlugin[])
891 } else if (first && 'sources' in first) {
892 sites = toRepoDataMihon(iconBase, json as MihonExtension[])
893 } else if (first && 'pkg' in first && 'apk' in first) {
894 sites = toRepoDataIReader(json as IReaderSource[])
895 } else if (first && 'iconUrl' in first && 'baseUrl' in first) {
896 sites = toRepoDataMangayomi(json as MangayomiSource[])
897 } else {
898 sites = toRepoDataAidokuLegacy(iconBase, json as AidokuLegacySource[])
899 }
900 } else if (Array.isArray((json as CloudstreamRepo).pluginLists)) {
901 sites = await toRepoDataCloudstream(json as CloudstreamRepo)
902 } else if ((json as AidokuIndex).sources?.length && 'iconURL' in (json as AidokuIndex).sources[0]) {
903 sites = toRepoDataAidoku(iconBase, json as AidokuIndex)
904 } else if ((json as SuwatteCatalogIndex).sources?.length && 'thumbnail' in (json as SuwatteCatalogIndex).sources[0]) {
905 const result = toRepoDataSuwatte(iconBase, json as SuwatteCatalogIndex)
906 sites = result.sites
907 suwatteListUrl = result.listUrl
908 suwatteV6 = (json as SuwatteCatalogIndex).catalogVersion === undefined
909 } else if (Array.isArray((json as KotatsuIndex).sites)) {
910 sites = toRepoDataKotatsu(json as KotatsuIndex)
911 } else {
912 sites = toRepoDataPaperback(iconBase, json as PaperbackIndex)
913 }
914 sites.sort((a, b) => a.name.localeCompare(b.name))
915 return { sites, suwatteV6, suwatteListUrl }
916}
917
918export interface ExtensionRepoData {
919 sites: Record<string, RepoData>
920 soraAuthors: Record<string, SoraAuthorRepo[]>
921 echoAuthors: Record<string, EchoAuthorRepo[]>
922 repoLists: Record<string, RepoListEntry[]>
923}
924
925export declare const data: ExtensionRepoData
926
927export default {
928 watch: ['../**/*.md'],
929 async load(): Promise<ExtensionRepoData> {
930 const urls = collectIndexUrls()
931 const listUrls = collectRepoListUrls()
932 const listUrlSet = new Set(listUrls)
933 const sites: Record<string, RepoData> = {}
934 const soraAuthors: Record<string, SoraAuthorRepo[]> = {}
935 const echoAuthors: Record<string, EchoAuthorRepo[]> = {}
936 const repoLists: Record<string, RepoListEntry[]> = {}
937 await Promise.all(listUrls.map(async listUrl => {
938 const json = await fetchIndex(listUrl)
939 if (!isCloudstreamRepoList(json)) {
940 repoLists[listUrl] = []
941 return
942 }
943 const indexUrls = [...new Set(json.map(item => typeof item === 'string' ? item : item.url))]
944 const repoJsons = await Promise.all(indexUrls.map(url => fetchIndex(url)))
945 const entries: RepoListEntry[] = indexUrls.map((indexUrl, i) => ({
946 label: repoListLabel(indexUrl, repoJsons[i]),
947 indexUrl,
948 repoUrl: inferRepoUrl(indexUrl)
949 }))
950 entries.sort((a, b) => a.label.localeCompare(b.label))
951 repoLists[listUrl] = entries
952 await Promise.all(indexUrls.map(async (indexUrl, i) => {
953 if (indexUrl in sites) return
954 sites[indexUrl] = await toRepoData(indexUrl, repoJsons[i])
955 }))
956 }))
957 await Promise.all(urls.map(async url => {
958 if (listUrlSet.has(url)) return
959 if (url in sites) return
960 const json = await fetchIndex(url)
961 if (isSoraRepoIndex(json)) {
962 const result = await loadSoraRepoIndex(url, json)
963 sites[url] = { sites: result.sites }
964 soraAuthors[url] = result.authorRepos
965 Object.assign(sites, result.sitesByAuthor)
966 return
967 }
968 if (isEchoExtensionList(json)) {
969 const result = loadEchoExtensionList(url, json)
970 sites[url] = { sites: result.sites }
971 echoAuthors[url] = result.authorRepos
972 Object.assign(sites, result.sitesByAuthor)
973 return
974 }
975 sites[url] = await toRepoData(url, json)
976 }))
977 return { sites, soraAuthors, echoAuthors, repoLists }
978 }
979}
docs/ext/extensionRepos/aidoku.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('aidoku')
9 }
10}
docs/ext/extensionRepos/aniyomi.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('aniyomi')
9 }
10}
docs/ext/extensionRepos/attrs.ts added +16
@@ -0,0 +1,16 @@
1export function parseExtRepoAttrs(text: string): Record<string, string> {
2 const match = text.match(/\{([^}]*)\}/)
3 if (!match) return {}
4 const attrs: Record<string, string> = {}
5 for (const token of match[1].split(/[\s,]+/).filter(Boolean)) {
6 const eq = token.indexOf('=')
7 if (eq < 0) {
8 attrs[token] = 'true'
9 continue
10 }
11 const key = token.slice(0, eq)
12 const value = token.slice(eq + 1)
13 if (key && value) attrs[key] = value.replace(/^["']|["']$/g, '')
14 }
15 return attrs
16}
docs/ext/extensionRepos/cloudstreamrepo.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('cloudstreamrepo')
9 }
10}
docs/ext/extensionRepos/echo.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('echo')
9 }
10}
docs/ext/extensionRepos/hayase.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('hayase')
9 }
10}
docs/ext/extensionRepos/kotatsu.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('kotatsu')
9 }
10}
docs/ext/extensionRepos/legado.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('legado')
9 }
10}
docs/ext/extensionRepos/lnreader.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('lnreader')
9 }
10}
docs/ext/extensionRepos/mangayomi.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('mangayomi')
9 }
10}
docs/ext/extensionRepos/manual.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('manual')
9 }
10}
docs/ext/extensionRepos/mihon.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('mihon')
9 }
10}
docs/ext/extensionRepos/paperback.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('paperback')
9 }
10}
docs/ext/extensionRepos/parsers.ts added +952
@@ -0,0 +1,952 @@
1import type {
2 Rating,
3 RepoSite
4} from '../../.vitepress/theme/components/extrepo/types'
5
6interface MihonIndexSource {
7 id: string
8 name: string
9 language: string
10 homeUrl: string
11 mirrorUrls?: string[]
12}
13
14interface MihonIndexExtension {
15 name: string
16 packageName: string
17 resources: {
18 apkUrl: string
19 iconUrl: string
20 jarUrl: string
21 }
22 extensionLib: string
23 versionCode: string
24 versionName: string
25 contentWarning: string
26 sources: MihonIndexSource[]
27}
28
29interface MihonIndex {
30 name: string
31 badgeLabel: string
32 signingKey: string
33 contact?: {
34 website?: string
35 discord?: string
36 }
37 extensionList: {
38 extensions: MihonIndexExtension[]
39 }
40}
41
42export interface RepoData {
43 sites: RepoSite[]
44 suwatteV6?: boolean
45 suwatteListUrl?: string
46}
47
48interface MihonSource {
49 name: string
50 lang: string
51 baseUrl: string
52}
53
54interface MihonExtension {
55 pkg: string
56 nsfw?: number
57 sources?: MihonSource[]
58}
59
60interface AidokuSource {
61 name: string
62 iconURL: string
63 languages?: string[]
64 contentRating?: number
65 baseURL: string
66}
67
68interface AidokuIndex {
69 sources: AidokuSource[]
70}
71
72interface AidokuLegacySource {
73 name: string
74 icon: string
75 lang: string
76 nsfw?: number
77}
78
79interface PaperbackSource {
80 id: string
81 name: string
82 icon: string
83 language?: string
84 contentRating?: string
85 websiteBaseURL?: string
86}
87
88interface PaperbackIndex {
89 sources: PaperbackSource[]
90 builtWith?: { toolchain?: string }
91}
92
93interface CloudstreamRepo {
94 name?: string
95 pluginLists: string[]
96}
97
98interface CloudstreamRepoListItem {
99 url: string
100 verified?: boolean
101}
102
103export interface RepoListEntry {
104 label: string
105 indexUrl: string
106 repoUrl?: string
107}
108
109interface CloudstreamPlugin {
110 name: string
111 iconUrl?: string
112 language?: string
113}
114
115interface HayaseExtension {
116 name: string
117 icon?: string
118 languages?: string[]
119}
120
121interface LegadoBookSource {
122 bookSourceName: string
123 bookSourceUrl: string
124 bookSourceGroup?: string
125}
126
127interface LNReaderPlugin {
128 name: string
129 lang: string
130 url: string
131 iconUrl?: string
132}
133
134interface MangayomiSource {
135 name: string
136 lang: string
137 baseUrl: string
138 iconUrl?: string
139 isNsfw?: boolean
140}
141
142interface IReaderSource {
143 pkg: string
144 apk: string
145 name: string
146 lang: string
147 nsfw?: boolean
148}
149
150interface SuwatteCatalogSource {
151 name: string
152 website?: string
153 languages?: string[]
154 thumbnail?: string
155 path?: string
156}
157
158interface SuwatteCatalogIndex {
159 listUrl?: string
160 catalogVersion?: number
161 sources: SuwatteCatalogSource[]
162}
163
164interface KotatsuSite {
165 name: string
166 lang: string
167 url: string
168 icon: string
169 contentType: string
170 isBroken: boolean
171}
172
173interface KotatsuIndex {
174 sites: KotatsuSite[]
175}
176
177interface EchoExtension {
178 id: string
179 type: string
180 name: string
181 subtitle?: string
182 iconUrl?: string
183 url?: string
184 updateUrl: string
185}
186
187export interface EchoAuthorRepo {
188 label: string
189 repoUrl?: string
190 indexUrl: string
191}
192
193const FETCH_TIMEOUT_MS = 15000
194const FETCH_CONCURRENCY = 10
195
196export type FetchJson = (url: string) => Promise<unknown | undefined>
197
198export async function fetchJsonHttp(url: string): Promise<unknown | undefined> {
199 for (let attempt = 0; attempt < 2; attempt++) {
200 const ctrl = new AbortController()
201 const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS)
202 try {
203 const res = await fetch(url, { signal: ctrl.signal })
204 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
205 return (await res.json()) as unknown
206 } catch {
207 if (attempt === 1) return undefined
208 } finally {
209 clearTimeout(timer)
210 }
211 }
212 return undefined
213}
214
215async function mapLimit<T, R>(
216 items: T[],
217 limit: number,
218 fn: (item: T, i: number) => Promise<R>
219): Promise<R[]> {
220 const out: R[] = new Array(items.length)
221 let next = 0
222 const workers = Array.from(
223 { length: Math.min(limit, items.length) },
224 async () => {
225 while (next < items.length) {
226 const i = next++
227 out[i] = await fn(items[i], i)
228 }
229 }
230 )
231 await Promise.all(workers)
232 return out
233}
234
235function isCloudstreamRepoList(
236 json: unknown
237): json is Array<string | CloudstreamRepoListItem> {
238 if (!Array.isArray(json) || json.length === 0) return false
239 return json.every((item) => {
240 if (typeof item === 'string') return /^https?:\/\//.test(item)
241 if (item && typeof item === 'object') {
242 const rec = item as Record<string, unknown>
243 if (
244 'name' in rec || 'lang' in rec || 'baseUrl' in rec || 'baseURL' in rec
245 ) return false
246 return typeof rec.url === 'string' && /^https?:\/\//.test(rec.url)
247 }
248 return false
249 })
250}
251
252function inferRepoUrl(rawUrl: string): string | undefined {
253 try {
254 const u = new URL(rawUrl)
255 const parts = u.pathname.split('/').filter(Boolean)
256 if (u.hostname === 'raw.githubusercontent.com' && parts.length >= 2) {
257 return `https://github.com/${parts[0]}/${parts[1]}`
258 }
259 const dashRaw = u.pathname.indexOf('/-/raw/')
260 if (dashRaw > 0) return `${u.origin}${u.pathname.slice(0, dashRaw)}`
261 const rawSeg = parts.indexOf('raw')
262 if (rawSeg > 1) return `${u.origin}/${parts.slice(0, rawSeg).join('/')}`
263 } catch {
264 return undefined
265 }
266 return undefined
267}
268
269function inferLabel(rawUrl: string): string {
270 const repoUrl = inferRepoUrl(rawUrl)
271 if (repoUrl) {
272 try {
273 const parts = new URL(repoUrl).pathname.split('/').filter(Boolean)
274 if (parts.length >= 2) {
275 return `${parts[parts.length - 2]}/${parts[parts.length - 1]}`
276 }
277 if (parts.length === 1) return decodeURIComponent(parts[0])
278 } catch {
279 // fall through below
280 }
281 }
282 try {
283 const parts = new URL(rawUrl).pathname.split('/').filter(Boolean)
284 return decodeURIComponent(
285 parts[parts.length - 2] ?? parts[parts.length - 1] ?? rawUrl
286 )
287 } catch {
288 return rawUrl
289 }
290}
291
292function repoListLabel(indexUrl: string, repoJson: unknown): string {
293 if (repoJson && typeof repoJson === 'object' && !Array.isArray(repoJson)) {
294 const name = (repoJson as { name?: unknown }).name
295 if (typeof name === 'string' && name.trim() !== '') return name.trim()
296 }
297 return inferLabel(indexUrl)
298}
299
300function ratingFromLevel(level: number): Rating {
301 if (level >= 2) return 'nsfw'
302 if (level >= 1) return 'suggestive'
303 return 'safe'
304}
305
306const LANG_ALIASES: Record<string, string> = {
307 jp: 'ja',
308 english: 'en',
309 'bahasa indonesia': 'id',
310 español: 'es',
311 français: 'fr',
312 polski: 'pl',
313 português: 'pt',
314 'tiếng việt': 'vi',
315 türkçe: 'tr',
316 русский: 'ru',
317 українська: 'uk',
318 ไทย: 'th',
319 العربية: 'ar',
320 chinese: 'zh',
321 japanese: 'ja',
322 korean: 'ko',
323 french: 'fr',
324 german: 'de',
325 greek: 'el',
326 indonesian: 'id',
327 italian: 'it',
328 spanish: 'es',
329 turkish: 'tr',
330 polish: 'pl',
331 russian: 'ru',
332 portuguese: 'pt',
333 arabic: 'ar',
334 tamil: 'ta',
335 ukrainian: 'uk',
336 vietnamese: 'vi',
337 thai: 'th',
338 hindi: 'hi',
339 malay: 'ms',
340 serbian: 'sr'
341}
342
343const LANG_SUBSTRING_ALIASES: [RegExp, string][] = [
344 [/日语原版/, 'ja'],
345 [/中文|汉语|漢語|轻小说/, 'zh'],
346 [/日本語/, 'ja'],
347 [/한국어|조선말/, 'ko']
348]
349
350const langCache = new Map<string, string>()
351
352function normalizeLang(lang: string): string {
353 const hit = langCache.get(lang)
354 if (hit !== undefined) return hit
355 const cleaned = lang.replace(/[\u200E\u200F]/g, '').trim()
356 let out: string
357 if (cleaned === '') out = 'all'
358 else {
359 const exact = LANG_ALIASES[cleaned.toLowerCase()]
360 if (exact) out = exact
361 else {
362 out = cleaned.toLowerCase()
363 for (const [re, code] of LANG_SUBSTRING_ALIASES) {
364 if (re.test(cleaned)) {
365 out = code
366 break
367 }
368 }
369 if (out === 'multi') out = 'all'
370 }
371 }
372 if (langCache.size > 2000) langCache.clear()
373 langCache.set(lang, out)
374 return out
375}
376
377function sortSites(sites: RepoSite[]): RepoSite[] {
378 return sites.sort((a, b) => a.name.localeCompare(b.name))
379}
380
381function addSite(
382 seen: Set<string>,
383 key: string,
384 sites: RepoSite[],
385 site: RepoSite
386): void {
387 if (seen.has(key)) return
388 seen.add(key)
389 sites.push(site)
390}
391
392function toRepoDataMihon(
393 iconBase: string,
394 extensions: MihonExtension[]
395): RepoSite[] {
396 const seen = new Set<string>()
397 const sites: RepoSite[] = []
398 for (const ext of extensions) {
399 const icon = `${iconBase}/icon/${ext.pkg}.png`
400 for (const source of ext.sources ?? []) {
401 addSite(
402 seen,
403 `${source.name}::${source.lang}::${source.baseUrl}`,
404 sites,
405 {
406 name: source.name ?? ext.pkg,
407 lang: source.lang ?? 'all',
408 icon,
409 url: source.baseUrl ?? '',
410 rating: ext.nsfw === 1 ? 'nsfw' : 'safe'
411 }
412 )
413 }
414 }
415 return sites
416}
417
418function toRepoDataAidoku(iconBase: string, index: AidokuIndex): RepoSite[] {
419 const seen = new Set<string>()
420 const sites: RepoSite[] = []
421 for (const source of index.sources ?? []) {
422 const icon = `${iconBase}/${source.iconURL}`
423 const rating = ratingFromLevel(source.contentRating ?? 0)
424 const langs = source.languages?.length ? source.languages : ['all']
425 for (const rawLang of langs) {
426 const lang = normalizeLang(rawLang)
427 addSite(seen, `${source.name}::${lang}::${source.baseURL}`, sites, {
428 name: source.name,
429 lang,
430 icon,
431 url: source.baseURL,
432 rating
433 })
434 }
435 }
436 return sites
437}
438
439function toRepoDataPaperback(
440 iconBase: string,
441 index: PaperbackIndex
442): RepoSite[] {
443 const seen = new Set<string>()
444 const sites: RepoSite[] = []
445 const iconDir = index.builtWith?.toolchain?.startsWith('0.8')
446 ? 'includes'
447 : 'static'
448 for (const source of index.sources ?? []) {
449 const lang = normalizeLang(source.language ?? 'all')
450 const key = `${source.id}::${lang}`
451 if (seen.has(key)) continue
452 seen.add(key)
453 const icon = `${iconBase}/${source.id}/${iconDir}/${source.icon}`
454 const rating: Rating = source.contentRating === 'ADULT'
455 ? 'nsfw'
456 : source.contentRating === 'MATURE'
457 ? 'suggestive'
458 : 'safe'
459 sites.push({
460 name: source.name,
461 lang,
462 icon,
463 url: source.websiteBaseURL ?? '',
464 rating
465 })
466 }
467 return sites
468}
469
470function normalizeGoogleFaviconUrl(url: string): string {
471 return url.replace('%size%', '64')
472}
473
474async function toRepoDataCloudstream(
475 repo: CloudstreamRepo,
476 fetchJson: FetchJson
477): Promise<RepoSite[]> {
478 const seen = new Set<string>()
479 const sites: RepoSite[] = []
480 const lists = await mapLimit(
481 repo.pluginLists,
482 FETCH_CONCURRENCY,
483 url => fetchJson(url)
484 )
485 for (const list of lists) {
486 if (!Array.isArray(list)) continue
487 for (const plugin of list as CloudstreamPlugin[]) {
488 if (seen.has(plugin.name)) continue
489 seen.add(plugin.name)
490 const lang = normalizeLang(plugin.language ?? 'all')
491 const icon = plugin.iconUrl
492 ? normalizeGoogleFaviconUrl(plugin.iconUrl)
493 : ''
494 sites.push({ name: plugin.name, lang, icon, url: '', rating: 'safe' })
495 }
496 }
497 return sites
498}
499
500function toRepoDataAidokuLegacy(
501 iconBase: string,
502 sources: AidokuLegacySource[]
503): RepoSite[] {
504 const seen = new Set<string>()
505 const sites: RepoSite[] = []
506 for (const source of sources) {
507 const lang = normalizeLang(source.lang)
508 addSite(seen, `${source.name}::${lang}`, sites, {
509 name: source.name,
510 lang,
511 icon: `${iconBase}/icons/${source.icon}`,
512 url: '',
513 rating: ratingFromLevel(source.nsfw ?? 0)
514 })
515 }
516 return sites
517}
518
519function toRepoDataHayase(extensions: HayaseExtension[]): RepoSite[] {
520 const seen = new Set<string>()
521 const sites: RepoSite[] = []
522 for (const ext of extensions) {
523 const langs = ext.languages?.length ? ext.languages : ['all']
524 for (const rawLang of langs) {
525 const lang = normalizeLang(rawLang)
526 addSite(seen, `${ext.name}::${lang}`, sites, {
527 name: ext.name,
528 lang,
529 icon: ext.icon ?? '',
530 url: '',
531 rating: 'safe'
532 })
533 }
534 }
535 return sites
536}
537
538function toRepoDataLegado(sources: LegadoBookSource[]): RepoSite[] {
539 const seen = new Set<string>()
540 const sites: RepoSite[] = []
541 for (const source of sources) {
542 const lang = normalizeLang(source.bookSourceGroup ?? 'all')
543 addSite(seen, `${source.bookSourceName}::${lang}`, sites, {
544 name: source.bookSourceName,
545 lang,
546 icon: '',
547 url: source.bookSourceUrl,
548 rating: 'safe'
549 })
550 }
551 return sites
552}
553
554function toRepoDataMangayomi(sources: MangayomiSource[]): RepoSite[] {
555 const seen = new Set<string>()
556 const sites: RepoSite[] = []
557 for (const source of sources) {
558 const lang = normalizeLang(source.lang)
559 addSite(seen, `${source.name}::${lang}`, sites, {
560 name: source.name,
561 lang,
562 icon: source.iconUrl ?? '',
563 url: source.baseUrl,
564 rating: source.isNsfw ? 'nsfw' : 'safe'
565 })
566 }
567 return sites
568}
569
570function toRepoDataIReader(sources: IReaderSource[]): RepoSite[] {
571 const seen = new Set<string>()
572 const sites: RepoSite[] = []
573 for (const source of sources) {
574 const lang = normalizeLang(source.lang)
575 addSite(seen, `${source.name}::${lang}`, sites, {
576 name: source.name,
577 lang,
578 icon: '',
579 url: '',
580 rating: source.nsfw ? 'nsfw' : 'safe'
581 })
582 }
583 return sites
584}
585
586function toRepoDataSuwatte(
587 iconBase: string,
588 index: SuwatteCatalogIndex
589): { sites: RepoSite[]; listUrl: string } {
590 const seen = new Set<string>()
591 const sites: RepoSite[] = []
592 const listUrl = index.listUrl ?? iconBase
593 const isV6 = index.catalogVersion === undefined
594 for (const source of index.sources ?? []) {
595 const langs = source.languages?.length ? source.languages : ['all']
596 const icon = source.thumbnail
597 ? (/^https?:\/\//i.test(source.thumbnail)
598 ? source.thumbnail
599 : `${iconBase}/assets/${source.thumbnail}`)
600 : ''
601 const installUrl = source.path
602 ? (isV6
603 ? `suwatte://runner?url=${listUrl}&runner=${source.path}`
604 : `suwatte://AddSourceFromList?list=${listUrl}&source=${source.path}`)
605 : undefined
606 for (const rawLang of langs) {
607 const lang = normalizeLang(rawLang)
608 addSite(seen, `${source.name}::${lang}`, sites, {
609 name: source.name,
610 lang,
611 icon,
612 url: source.website ?? '',
613 rating: 'safe',
614 installUrl
615 })
616 }
617 }
618 return { sites, listUrl }
619}
620
621function toRepoDataKotatsu(index: KotatsuIndex): RepoSite[] {
622 const seen = new Set<string>()
623 const sites: RepoSite[] = []
624 for (const site of index.sites) {
625 const lang = normalizeLang(site.lang ?? 'all')
626 const contentType = site.contentType ?? ''
627 const rating: Rating = contentType.includes('HENTAI') ? 'nsfw' : 'safe'
628 addSite(seen, `${site.name}::${lang}::${site.url}`, sites, {
629 name: site.name ?? 'Unknown',
630 lang,
631 icon: site.icon,
632 url: site.url ?? '',
633 rating,
634 contentType,
635 isBroken: site.isBroken || undefined
636 })
637 }
638 return sites
639}
640
641function isEchoExtensionList(json: unknown): json is EchoExtension[] {
642 if (!Array.isArray(json) || json.length === 0) return false
643 const first = json[0] as Record<string, unknown>
644 return typeof first.updateUrl === 'string' &&
645 typeof first.subtitle === 'string' && !('lang' in first) &&
646 !('baseUrl' in first)
647}
648
649function parseEchoRepo(
650 updateUrl: string
651): {
652 host: string
653 owner: string
654 repo: string
655 repoUrl: string
656 ownerUrl: string
657} | undefined {
658 const githubMatch = updateUrl.match(
659 /^https:\/\/api\.github\.com\/repos\/([^/]+)\/([^/]+)\/releases$/
660 )
661 if (githubMatch) {
662 const [, owner, repo] = githubMatch
663 return {
664 host: 'github.com',
665 owner,
666 repo,
667 repoUrl: `https://github.com/${owner}/${repo}`,
668 ownerUrl: `https://github.com/${owner}`
669 }
670 }
671 const gitlabMatch = updateUrl.match(
672 /^https:\/\/(gitlab\.com)\/api\/v4\/projects\/([^/]+)\/releases\b/
673 )
674 if (gitlabMatch) {
675 const [, host, encodedPath] = gitlabMatch
676 const path = decodeURIComponent(encodedPath)
677 const owner = path.slice(0, path.lastIndexOf('/'))
678 const repo = path.slice(path.lastIndexOf('/') + 1)
679 if (!owner || !repo) return undefined
680 return {
681 host,
682 owner,
683 repo,
684 repoUrl: `https://${host}/${path}`,
685 ownerUrl: `https://${host}/${owner}`
686 }
687 }
688 return undefined
689}
690
691function toRepoDataEchoExtensions(extensions: EchoExtension[]): RepoSite[] {
692 const seen = new Set<string>()
693 const sites: RepoSite[] = []
694 for (const ext of extensions) {
695 if (seen.has(`${ext.id}::${ext.updateUrl}`)) continue
696 seen.add(`${ext.id}::${ext.updateUrl}`)
697 const repo = parseEchoRepo(ext.updateUrl)
698 sites.push({
699 name: ext.name,
700 lang: 'all',
701 icon: ext.iconUrl ?? '',
702 url: ext.url ?? repo?.repoUrl ?? '',
703 rating: 'safe',
704 contentType: ext.type,
705 installUrl: repo?.repoUrl
706 })
707 }
708 return sortSites(sites)
709}
710
711function loadEchoExtensionList(
712 indexUrl: string,
713 extensions: EchoExtension[]
714): {
715 sites: RepoSite[]
716 authorRepos: EchoAuthorRepo[]
717 sitesByAuthor: Record<string, RepoData>
718} {
719 const byAuthor = new Map<
720 string,
721 { label: string; ownerUrl?: string; exts: EchoExtension[] }
722 >()
723 for (const ext of extensions) {
724 const repo = parseEchoRepo(ext.updateUrl)
725 const key = repo ? `${repo.host}:${repo.owner}` : 'Unknown'
726 const bucket = byAuthor.get(key)
727 if (bucket) bucket.exts.push(ext)
728 else {byAuthor.set(key, {
729 label: repo?.owner ?? 'Unknown',
730 ownerUrl: repo?.ownerUrl,
731 exts: [ext]
732 })}
733 }
734 const authorRepos: EchoAuthorRepo[] = []
735 const sitesByAuthor: Record<string, RepoData> = {}
736 for (const [key, { label, ownerUrl, exts }] of byAuthor) {
737 const authorIndexUrl = `${indexUrl}#${key}`
738 sitesByAuthor[authorIndexUrl] = { sites: toRepoDataEchoExtensions(exts) }
739 authorRepos.push({ label, repoUrl: ownerUrl, indexUrl: authorIndexUrl })
740 }
741 authorRepos.sort((a, b) => a.label.localeCompare(b.label))
742 return {
743 sites: toRepoDataEchoExtensions(extensions),
744 authorRepos,
745 sitesByAuthor
746 }
747}
748
749function toRepoDataLNReader(plugins: LNReaderPlugin[]): RepoSite[] {
750 const seen = new Set<string>()
751 const sites: RepoSite[] = []
752 for (const plugin of plugins) {
753 const lang = normalizeLang(plugin.lang)
754 addSite(seen, `${plugin.name}::${lang}`, sites, {
755 name: plugin.name,
756 lang,
757 icon: plugin.iconUrl ?? '',
758 url: plugin.url,
759 rating: 'safe'
760 })
761 }
762 return sites
763}
764
765const CONTENT_WARNING_RATING: Record<string, Rating> = {
766 CONTENT_WARNING_NSFW: 'nsfw',
767 CONTENT_WARNING_MIXED: 'suggestive',
768 CONTENT_WARNING_SAFE: 'safe'
769}
770
771function toRepoDataMihonNew(index: MihonIndex): RepoSite[] {
772 const seen = new Set<string>()
773 const sites: RepoSite[] = []
774 for (const ext of index.extensionList.extensions) {
775 const icon = ext.resources.iconUrl
776 const rating = CONTENT_WARNING_RATING[ext.contentWarning] ?? 'safe'
777 for (const source of ext.sources) {
778 addSite(
779 seen,
780 `${source.name}::${source.language}::${source.homeUrl}`,
781 sites,
782 {
783 name: source.name ?? 'Unknown',
784 lang: source.language ?? 'all',
785 icon,
786 url: source.homeUrl ?? '',
787 rating
788 }
789 )
790 }
791 }
792 return sortSites(sites)
793}
794
795async function toRepoData(
796 indexUrl: string,
797 json: unknown,
798 fetchJson: FetchJson
799): Promise<RepoData> {
800 const iconBase = indexUrl.slice(0, indexUrl.lastIndexOf('/'))
801 let sites: RepoSite[]
802 let suwatteV6: boolean | undefined
803 let suwatteListUrl: string | undefined
804
805 if (
806 json && typeof json === 'object' && !Array.isArray(json) &&
807 'extensionList' in (json as Record<string, unknown>)
808 ) {
809 return { sites: toRepoDataMihonNew(json as MihonIndex) }
810 }
811
812 if (Array.isArray(json)) {
813 const first = json[0] as Record<string, unknown> | undefined
814 if (first && 'bookSourceUrl' in first) {
815 sites = toRepoDataLegado(json as LegadoBookSource[])
816 } else if (first && 'manifestVersion' in first) {
817 sites = toRepoDataHayase(json as HayaseExtension[])
818 } else if (first && 'iconUrl' in first && 'site' in first) {
819 sites = toRepoDataLNReader(json as LNReaderPlugin[])
820 } else if (first && 'sources' in first) {
821 sites = toRepoDataMihon(iconBase, json as MihonExtension[])
822 } else if (first && 'pkg' in first && 'apk' in first) {
823 sites = toRepoDataIReader(json as IReaderSource[])
824 } else if (first && 'iconUrl' in first && 'baseUrl' in first) {
825 sites = toRepoDataMangayomi(json as MangayomiSource[])
826 } else {
827 sites = toRepoDataAidokuLegacy(iconBase, json as AidokuLegacySource[])
828 }
829 } else if (Array.isArray((json as CloudstreamRepo).pluginLists)) {
830 sites = await toRepoDataCloudstream(json as CloudstreamRepo, fetchJson)
831 } else if (
832 (json as AidokuIndex).sources?.length &&
833 'iconURL' in (json as AidokuIndex).sources[0]
834 ) {
835 sites = toRepoDataAidoku(iconBase, json as AidokuIndex)
836 } else if (
837 (json as SuwatteCatalogIndex).sources?.length &&
838 'thumbnail' in (json as SuwatteCatalogIndex).sources[0]
839 ) {
840 const result = toRepoDataSuwatte(iconBase, json as SuwatteCatalogIndex)
841 sites = result.sites
842 suwatteListUrl = result.listUrl
843 suwatteV6 = (json as SuwatteCatalogIndex).catalogVersion === undefined
844 } else if (Array.isArray((json as KotatsuIndex).sites)) {
845 sites = toRepoDataKotatsu(json as KotatsuIndex)
846 } else {
847 sites = toRepoDataPaperback(iconBase, json as PaperbackIndex)
848 }
849 return { sites: sortSites(sites), suwatteV6, suwatteListUrl }
850}
851
852export interface ExtensionRepoData {
853 sites: Record<string, RepoData>
854 echoAuthors: Record<string, EchoAuthorRepo[]>
855 repoLists: Record<string, RepoListEntry[]>
856}
857
858export async function assembleSchemeData(
859 indexUrls: string[],
860 listUrls: string[],
861 fetchJson: FetchJson
862): Promise<ExtensionRepoData> {
863 const listUrlSet = new Set(listUrls)
864 const sites: Record<string, RepoData> = {}
865 const echoAuthors: Record<string, EchoAuthorRepo[]> = {}
866 const repoLists: Record<string, RepoListEntry[]> = {}
867 const pendingByAuthor: Record<string, RepoData> = {}
868
869 const listJsons = await mapLimit(
870 listUrls,
871 FETCH_CONCURRENCY,
872 url => fetchJson(url)
873 )
874 const listIndexGroups: {
875 indexUrls: string[]
876 repoJsons: unknown[]
877 failed: boolean
878 }[] = await Promise.all(listJsons.map(async (json) => {
879 if (json === undefined) {
880 return { indexUrls: [], repoJsons: [], failed: true }
881 }
882 if (!isCloudstreamRepoList(json)) {
883 return { indexUrls: [], repoJsons: [], failed: false }
884 }
885 const indexUrls = [
886 ...new Set(
887 json.map(item => typeof item === 'string' ? item : item.url)
888 )
889 ]
890 const repoJsons = await mapLimit(
891 indexUrls,
892 FETCH_CONCURRENCY,
893 url => fetchJson(url)
894 )
895 return { indexUrls, repoJsons, failed: false }
896 }))
897 listUrls.forEach((listUrl, li) => {
898 const { indexUrls, repoJsons, failed } = listIndexGroups[li]
899 if (failed) return
900 if (indexUrls.length === 0) {
901 repoLists[listUrl] = []
902 return
903 }
904 const entries: RepoListEntry[] = indexUrls.map((indexUrl, i) => ({
905 label: repoListLabel(indexUrl, repoJsons[i]),
906 indexUrl,
907 repoUrl: inferRepoUrl(indexUrl)
908 }))
909 entries.sort((a, b) => a.label.localeCompare(b.label))
910 repoLists[listUrl] = entries
911 })
912 const listRepoPairs = listIndexGroups.filter(g => !g.failed).flatMap(g =>
913 g.indexUrls.map((url, i) => ({ url, json: g.repoJsons[i] })).filter(p =>
914 p.json !== undefined
915 )
916 )
917 const listRepoResults = await mapLimit(
918 listRepoPairs,
919 FETCH_CONCURRENCY,
920 async ({ url, json }) => ({
921 url,
922 data: await toRepoData(url, json, fetchJson)
923 })
924 )
925 for (const { url, data } of listRepoResults) {
926 if (!(url in sites)) sites[url] = data
927 }
928
929 const remaining = indexUrls.filter(url =>
930 !listUrlSet.has(url) && !(url in sites)
931 )
932 const jsons = await mapLimit(
933 remaining,
934 FETCH_CONCURRENCY,
935 url => fetchJson(url)
936 )
937 for (let i = 0; i < remaining.length; i++) {
938 const url = remaining[i]
939 const json = jsons[i]
940 if (json === undefined) continue
941 if (isEchoExtensionList(json)) {
942 const result = loadEchoExtensionList(url, json)
943 sites[url] = { sites: result.sites }
944 echoAuthors[url] = result.authorRepos
945 Object.assign(pendingByAuthor, result.sitesByAuthor)
946 continue
947 }
948 sites[url] = await toRepoData(url, json, fetchJson)
949 }
950 Object.assign(sites, pendingByAuthor)
951 return { sites, echoAuthors, repoLists }
952}
docs/ext/extensionRepos/shared.ts added +178
@@ -0,0 +1,178 @@
1import {
2 existsSync,
3 mkdirSync,
4 readdirSync,
5 readFileSync,
6 renameSync,
7 statSync,
8 writeFileSync
9} from 'node:fs'
10import { dirname, join } from 'node:path'
11import { fileURLToPath } from 'node:url'
12import { parseExtRepoAttrs } from './attrs'
13import { assembleSchemeData, type ExtensionRepoData } from './parsers'
14
15export type { ExtensionRepoData } from './parsers'
16
17const IGNORED_DIRS = new Set(['node_modules', '.vitepress', '.git'])
18const FETCH_TIMEOUT_MS = 15000
19const CACHE_TTL_MS = 6 * 60 * 60 * 1000
20
21const EXT_DIR = dirname(fileURLToPath(import.meta.url))
22const DOCS_DIR = join(EXT_DIR, '..', '..')
23const CACHE_DIR = join(EXT_DIR, '..', '..', '.vitepress/cache/extension-repos')
24let cacheDirReady = false
25
26function findMarkdownFiles(dir: string): string[] {
27 const files: string[] = []
28 for (const entry of readdirSync(dir, { withFileTypes: true })) {
29 if (entry.isDirectory()) {
30 if (!IGNORED_DIRS.has(entry.name)) {
31 files.push(...findMarkdownFiles(join(dir, entry.name)))
32 }
33 } else if (entry.name.endsWith('.md')) {
34 files.push(join(dir, entry.name))
35 }
36 }
37 return files
38}
39
40// Single scan of all md files, collecting urls for one scheme only.
41function collectScheme(
42 scheme: string
43): { indexUrls: string[]; listUrls: string[] } {
44 const indexUrls = new Set<string>()
45 const listUrls = new Set<string>()
46 const blockRe = /:::\s*extrepo([^\n]*)\n([\s\S]*?)\n\s*:::/g
47 const rowRe =
48 /^\s*-\s*(raw|manga|anime|novel|data)\s*:\s*(https?:\/\/\S+)\s*$/i
49 const headingRe = /^\s*==\s+.+$/
50 const buildRe = /^\s*--\s+.+$/
51
52 function flushEntry(
53 plainRaws: string[],
54 variantUrls: string[],
55 buildRaws: string[],
56 dataUrls: string[]
57 ): void {
58 for (const url of variantUrls) indexUrls.add(url)
59 for (const url of buildRaws) indexUrls.add(url)
60 for (const url of dataUrls) indexUrls.add(url)
61 if (dataUrls.length === 0) {
62 for (const url of plainRaws) indexUrls.add(url)
63 }
64 }
65
66 for (const file of findMarkdownFiles(DOCS_DIR)) {
67 const src = readFileSync(file, 'utf-8')
68 let block: RegExpExecArray | null
69 blockRe.lastIndex = 0
70 while ((block = blockRe.exec(src))) {
71 const headerAttrs = parseBlockAttrs(block[1])
72 if ((headerAttrs.scheme || 'mihon') !== scheme) continue
73 if (headerAttrs.from) listUrls.add(headerAttrs.from)
74 let plainRaws: string[] = []
75 let variantUrls: string[] = []
76 let buildRaws: string[] = []
77 let dataUrls: string[] = []
78 let inEntry = false
79 let inBuild = false
80 for (const line of block[2].split('\n')) {
81 if (headingRe.test(line)) {
82 if (inEntry) flushEntry(plainRaws, variantUrls, buildRaws, dataUrls)
83 plainRaws = []
84 variantUrls = []
85 buildRaws = []
86 dataUrls = []
87 inEntry = true
88 inBuild = false
89 continue
90 }
91 if (buildRe.test(line)) {
92 inBuild = true
93 continue
94 }
95 const row = rowRe.exec(line)
96 if (row && inEntry) {
97 const key = row[1].toLowerCase()
98 const url = row[2].trim()
99 if (key === 'data') dataUrls.push(url)
100 else if (key === 'raw') (inBuild ? buildRaws : plainRaws).push(url)
101 else variantUrls.push(url)
102 }
103 }
104 if (inEntry) flushEntry(plainRaws, variantUrls, buildRaws, dataUrls)
105 }
106 }
107 return { indexUrls: [...indexUrls], listUrls: [...listUrls] }
108}
109
110function parseBlockAttrs(header: string): { scheme?: string; from?: string } {
111 const attrs = parseExtRepoAttrs(header)
112 return { scheme: attrs.scheme, from: attrs.from }
113}
114
115function cachePathFor(url: string): string {
116 return join(CACHE_DIR, `${Buffer.from(url).toString('base64url')}.json`)
117}
118
119const inflight = new Map<string, Promise<unknown>>()
120
121async function fetchOnce(url: string): Promise<unknown> {
122 const cachePath = cachePathFor(url)
123 if (
124 existsSync(cachePath) &&
125 Date.now() - statSync(cachePath).mtimeMs < CACHE_TTL_MS
126 ) {
127 return JSON.parse(readFileSync(cachePath, 'utf-8'))
128 }
129 const ctrl = new AbortController()
130 const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS)
131 try {
132 const res = await fetch(url, { signal: ctrl.signal })
133 if (!res.ok) throw new Error(`${res.status} ${res.statusText}`)
134 const json = await res.json()
135 if (!cacheDirReady) {
136 mkdirSync(CACHE_DIR, { recursive: true })
137 cacheDirReady = true
138 }
139 const tmp = `${cachePath}.${process.pid}.tmp`
140 writeFileSync(tmp, JSON.stringify(json))
141 renameSync(tmp, cachePath)
142 return json
143 } finally {
144 clearTimeout(timer)
145 }
146}
147
148function fetchIndex(url: string): Promise<unknown> {
149 const hit = inflight.get(url)
150 if (hit) return hit
151 const p = (async () => {
152 for (let attempt = 0; attempt < 2; attempt++) {
153 try {
154 return await fetchOnce(url)
155 } catch (err) {
156 if (attempt === 1) {
157 const cachePath = cachePathFor(url)
158 if (existsSync(cachePath)) {
159 return JSON.parse(readFileSync(cachePath, 'utf-8'))
160 }
161 console.warn(
162 `[extrepo] failed to fetch ${url}: ${(err as Error).message}`
163 )
164 return []
165 }
166 }
167 }
168 })() as Promise<unknown>
169 inflight.set(url, p)
170 return p
171}
172
173export async function loadScheme(
174 scheme: string
175): Promise<ExtensionRepoData> {
176 const { indexUrls, listUrls } = collectScheme(scheme)
177 return assembleSchemeData(indexUrls, listUrls, fetchIndex)
178}
docs/ext/extensionRepos/suwatte.data.ts added +10
@@ -0,0 +1,10 @@
1import { type ExtensionRepoData, loadScheme } from './shared'
2
3export declare const data: ExtensionRepoData
4
5export default {
6 watch: ['../../**/*.md'],
7 async load(): Promise<ExtensionRepoData> {
8 return loadScheme('suwatte')
9 }
10}
docs/ext/index.md +1 −1
@@ -32,7 +32,7 @@ og:
32 32
33## Cross-app Support 33## Cross-app Support
34::: scrapetable 34::: scrapetable
35- Anymex : (Mihon), (Aniyomi), (Mangayomi), (Kotatsu), (Sora), (Cloudstream), (LNReader); 35- Anymex : (Mihon), (Aniyomi), (Mangayomi), (Kotatsu), (Cloudstream), (LNReader);
36- Cloudstream : (Cloudstream), (Aniyomi); 36- Cloudstream : (Cloudstream), (Aniyomi);
37- Dantotsu : (Mihon), (Aniyomi), (LNreader); 37- Dantotsu : (Mihon), (Aniyomi), (LNreader);
38- Futon : (Kotatsu), (Mihon); 38- Futon : (Kotatsu), (Mihon);
docs/ext/ios.md +1 −10
@@ -1,6 +1,6 @@
1--- 1---
2title: iOS Apps Extension Repos 2title: iOS Apps Extension Repos
3customDescription: Extension Repos & Guides for Aidoku, Sora & Suwatte 3customDescription: Extension Repos & Guides for Aidoku, Paperback & Suwatte
4feedback: no 4feedback: no
5og: 5og:
6 image: /embed/ios.png 6 image: /embed/ios.png
@@ -139,15 +139,6 @@ og:
139You can install v0.8 extensions in the v0.9 Paperback client, but you can't install v0.9 extensions in the v0.8 client. 139You can install v0.8 extensions in the v0.9 Paperback client, but you can't install v0.9 extensions in the v0.8 client.
140::: 140:::
141 141
142## Sora
143
144::: extrepo {scheme=sora}
145
146== Sources
147- raw: https://kotatsu-83g.pages.dev/sora/index.json
148
149:::
150
151## Suwatte 142## Suwatte
152 143
153::: extrepo {scheme=suwatte} 144::: extrepo {scheme=suwatte}
docs/ext/mihon.md +1 −1
@@ -26,7 +26,7 @@ og:
26 26
27## Manga 27## Manga
28 28
29::: extrepo {scheme=mihon} 29::: extrepo {scheme=mihon,manual}
30 30
31== Keiyoushi 31== Keiyoushi
32- url: https://keiyoushi.github.io/ 32- url: https://keiyoushi.github.io/
unocss.config.ts +3
@@ -79,6 +79,9 @@ const safelist = [
79 'i-lucide:message-circle', 79 'i-lucide:message-circle',
80 'i-lucide:copy', 80 'i-lucide:copy',
81 'i-lucide:check', 81 'i-lucide:check',
82 'i-lucide:x',
83 'i-lucide:loader-circle',
84 'i-lucide:refresh-cw',
82 'i-lucide:settings', 85 'i-lucide:settings',
83 'i-lucide:download', 86 'i-lucide:download',
84 'i-lucide:chevron-down', 87 'i-lucide:chevron-down',