修复搜索结果显示

This commit is contained in:
NewName
2025-05-20 17:04:13 +08:00
parent fc185c29ed
commit 0081f825e5
2 changed files with 19 additions and 21 deletions

View File

@@ -574,31 +574,27 @@
card.className = 'result-card';
// 确保所有字段都有值
const name = result.name || '';
const namespace = result.namespace || '';
const description = result.description || '暂无描述';
const name = result.repo_name || '';
const description = result.short_description || '暂无描述';
const starCount = result.star_count || 0;
const pullCount = result.pull_count || 0;
const lastUpdated = result.last_updated || new Date();
const repoName = namespace ? `${namespace}/${name}` : name;
const repoOwner = result.repo_owner || '';
const repoName = name;
const officialBadge = result.is_official ? '<span class="badge badge-official">官方</span>' : '';
const orgBadge = result.organization ? `<span class="badge badge-organization">By ${result.organization}</span>` : '';
const automatedBadge = result.is_automated ? '<span class="badge badge-automated">自动构建</span>' : '';
console.log('处理仓库:', {
name,
namespace,
repoOwner,
repoName,
isOfficial: result.is_official,
organization: result.organization
isAutomated: result.is_automated
});
card.innerHTML = `
<div class="result-title">
${repoName}
${officialBadge}
${orgBadge}
${automatedBadge}
</div>
<div class="result-description">${description}</div>
<div class="result-meta">
@@ -606,14 +602,14 @@
${starCount > 0 ? `<span class="meta-item">⭐ ${formatNumber(starCount)}</span>` : ''}
${pullCount > 0 ? `<span class="meta-item">⬇️ ${formatNumber(pullCount)}</span>` : ''}
</span>
<span class="meta-item">更新于 ${formatTimeAgo(lastUpdated)}</span>
<span class="meta-item">更新于 ${formatTimeAgo(result.last_updated)}</span>
</div>
`;
card.addEventListener('click', () => {
console.log('点击仓库:', name, namespace);
console.log('点击仓库:', name, repoOwner);
currentRepo = result;
loadTags(namespace || 'library', name);
loadTags(repoOwner, name);
});
resultsContainer.appendChild(card);
@@ -657,8 +653,6 @@
<div class="tag-title">
${repoName}
${currentRepo.is_official ? '<span class="badge badge-official">官方</span>' : ''}
${currentRepo.organization ? `<span class="badge badge-organization">By ${currentRepo.organization}</span>` : ''}
${currentRepo.is_automated ? '<span class="badge badge-automated">自动构建</span>' : ''}
</div>
<div class="tag-description">${currentRepo.description || '暂无描述'}</div>
<div class="tag-meta">

View File

@@ -24,16 +24,13 @@ type SearchResult struct {
// Repository 仓库信息
type Repository struct {
Name string `json:"name"`
Namespace string `json:"namespace"`
Description string `json:"description"`
Name string `json:"repo_name"`
Description string `json:"short_description"`
IsOfficial bool `json:"is_official"`
IsAutomated bool `json:"is_automated"`
StarCount int `json:"star_count"`
PullCount int `json:"pull_count"`
LastUpdated time.Time `json:"last_updated"`
Status int `json:"status"`
Organization string `json:"organization,omitempty"`
RepoOwner string `json:"repo_owner"`
}
// TagInfo 标签信息
@@ -269,6 +266,13 @@ 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/")
}
}
c.JSON(http.StatusOK, result)
})