feat(plugin): show local repo paths in repository filter

This commit is contained in:
InfinityPacer
2026-04-19 04:20:49 +08:00
parent 7b20a7b775
commit b54e144d0e
+15 -5
View File
@@ -613,9 +613,9 @@ async function saveFolderPluginOrder() {
// 初始化过滤选项 // 初始化过滤选项
function initOptions(item: Plugin) { function initOptions(item: Plugin) {
const optionValue = (options: Array<string>, value: string | undefined) => { const optionValue = (options: Array<string>, value: string | undefined, preferred = false) => {
if (!value || options.includes(value)) return if (!value || options.includes(value)) return
if (value === localRepoLabel.value) options.unshift(value) if (preferred) options.unshift(value)
else options.push(value) else options.push(value)
} }
const optionMutipleValue = (options: Array<string>, value: string | undefined) => { const optionMutipleValue = (options: Array<string>, value: string | undefined) => {
@@ -623,7 +623,7 @@ function initOptions(item: Plugin) {
} }
optionValue(authorFilterOptions.value, item.plugin_author) optionValue(authorFilterOptions.value, item.plugin_author)
optionMutipleValue(labelFilterOptions.value, item.plugin_label) optionMutipleValue(labelFilterOptions.value, item.plugin_label)
optionValue(repoFilterOptions.value, handleRepoUrl(item)) optionValue(repoFilterOptions.value, handleRepoUrl(item), Boolean(item.is_local || item.repo_url?.startsWith('local://')))
} }
// 关闭插件市场窗口 // 关闭插件市场窗口
@@ -856,12 +856,22 @@ async function refreshMarket() {
} }
} }
function parseLocalRepoPath(repoUrl: string | undefined) {
if (!repoUrl?.startsWith('local://')) return ''
try {
return new URL(repoUrl).searchParams.get('path') || ''
} catch (error) {
return decodeURIComponent(repoUrl.match(/[?&]path=([^&]+)/)?.[1] || '')
}
}
// 处理掉github地址的前缀 // 处理掉github地址的前缀
function handleRepoUrl(item: Plugin | string | undefined) { function handleRepoUrl(item: Plugin | string | undefined) {
const url = typeof item === 'string' ? item : item?.repo_url const url = typeof item === 'string' ? item : item?.repo_url
if (typeof item !== 'string' && item?.is_local) return localRepoLabel.value
if (!url) return '' if (!url) return ''
if (url.startsWith('local://')) return localRepoLabel.value if (url.startsWith('local://')) return parseLocalRepoPath(url) || localRepoLabel.value
if (typeof item !== 'string' && item?.is_local) return parseLocalRepoPath(url) || localRepoLabel.value
return url.replace('https://github.com/', '').replace('https://raw.githubusercontent.com/', '') return url.replace('https://github.com/', '').replace('https://raw.githubusercontent.com/', '')
} }