diff --git a/ghproxy/public/search.html b/ghproxy/public/search.html index f592ec2..dacd6b3 100644 --- a/ghproxy/public/search.html +++ b/ghproxy/public/search.html @@ -123,22 +123,32 @@ .result-meta { display: flex; justify-content: space-between; - align-items: center; + align-items: flex-start; font-size: 0.9rem; color: var(--fontcolor); opacity: 0.8; margin-top: 15px; + flex-wrap: wrap; + gap: 10px; } .meta-stats { display: flex; align-items: center; gap: 15px; + flex-wrap: wrap; } .meta-pulls { font-size: 0.85rem; color: #666; + text-align: right; + } + + .meta-pulls .pulls-count { + font-size: 1rem; + color: #333; + margin-top: 4px; } .badge { @@ -378,6 +388,18 @@ .back-to-search:hover { text-decoration: underline; } + + @media (max-width: 768px) { + .result-meta { + flex-direction: column; + align-items: flex-start; + } + + .meta-pulls { + text-align: left; + width: 100%; + } + }
@@ -536,7 +558,25 @@ if (!dateString) return '未知时间'; const date = new Date(dateString); - if (isNaN(date.getTime())) return '未知时间'; + if (isNaN(date.getTime())) { + // 尝试解析其他日期格式 + const formats = [ + 'YYYY-MM-DD', + 'YYYY/MM/DD', + 'MM/DD/YYYY', + 'DD/MM/YYYY' + ]; + + for (const format of formats) { + const d = tryParseDate(dateString, format); + if (d && !isNaN(d.getTime())) { + date = d; + break; + } + } + + if (isNaN(date.getTime())) return '未知时间'; + } const now = new Date(); const diffTime = Math.abs(now - date); @@ -546,6 +586,7 @@ const diffMonths = Math.floor(diffDays / 30); const diffYears = Math.floor(diffDays / 365); + if (diffMinutes < 5) return '几秒前'; if (diffMinutes < 60) return `${diffMinutes}分钟前`; if (diffHours < 24) return `${diffHours}小时前`; if (diffDays < 7) return `${diffDays}天前`; @@ -554,6 +595,21 @@ return `${diffYears}年前`; } + function tryParseDate(dateString, format) { + const parts = dateString.split(/[-/]/); + const formatParts = format.split(/[-/]/); + const dateObj = {}; + + for (let i = 0; i < formatParts.length; i++) { + const part = formatParts[i].toUpperCase(); + if (part === 'YYYY') dateObj.year = parseInt(parts[i]); + else if (part === 'MM') dateObj.month = parseInt(parts[i]) - 1; + else if (part === 'DD') dateObj.day = parseInt(parts[i]); + } + + return new Date(dateObj.year, dateObj.month, dateObj.day); + } + function displayResults(results) { const resultsContainer = document.getElementById('searchResults'); resultsContainer.innerHTML = ''; @@ -563,6 +619,14 @@ return; } + // 对结果进行排序:官方镜像优先,然后按照拉取次数排序 + results.sort((a, b) => { + if (a.is_official !== b.is_official) { + return b.is_official - a.is_official; + } + return b.pull_count - a.pull_count; + }); + results.forEach(result => { const card = document.createElement('div'); card.className = 'result-card'; @@ -597,14 +661,14 @@ ${pullsLastWeek > 0 ? ` ` : ''} `; card.addEventListener('click', () => { - console.log('点击仓库:', name); currentRepo = result; loadTags(result.is_official ? 'library' : (result.repo_owner || ''), name); }); diff --git a/ghproxy/search.go b/ghproxy/search.go index fc649d4..17f72d2 100644 --- a/ghproxy/search.go +++ b/ghproxy/search.go @@ -258,7 +258,7 @@ func RegisterSearchRoute(r *gin.Engine) { // 如果是搜索官方镜像 if !strings.Contains(query, "/") { - query = "library/" + query + query = strings.ToLower(query) } fmt.Printf("搜索请求: query=%s, page=%d, pageSize=%d\n", query, page, pageSize) @@ -270,12 +270,22 @@ func RegisterSearchRoute(r *gin.Engine) { return } - // 处理官方镜像的情况 - for i := range result.Results { - if result.Results[i].IsOfficial { - result.Results[i].Name = strings.TrimPrefix(result.Results[i].Name, "library/") + // 过滤搜索结果,只保留相关的镜像 + filteredResults := make([]Repository, 0) + searchTerm := strings.ToLower(strings.TrimPrefix(query, "library/")) + + for _, repo := range result.Results { + repoName := strings.ToLower(repo.Name) + // 如果是精确匹配或者以搜索词开头,或者包含 "searchTerm/searchTerm" + if repoName == searchTerm || + strings.HasPrefix(repoName, searchTerm+"/") || + strings.Contains(repoName, "/"+searchTerm) { + filteredResults = append(filteredResults, repo) } } + + result.Results = filteredResults + result.Count = len(filteredResults) c.JSON(http.StatusOK, result) })