修复搜索结果显示
This commit is contained in:
@@ -574,31 +574,27 @@
|
|||||||
card.className = 'result-card';
|
card.className = 'result-card';
|
||||||
|
|
||||||
// 确保所有字段都有值
|
// 确保所有字段都有值
|
||||||
const name = result.name || '';
|
const name = result.repo_name || '';
|
||||||
const namespace = result.namespace || '';
|
const description = result.short_description || '暂无描述';
|
||||||
const description = result.description || '暂无描述';
|
|
||||||
const starCount = result.star_count || 0;
|
const starCount = result.star_count || 0;
|
||||||
const pullCount = result.pull_count || 0;
|
const pullCount = result.pull_count || 0;
|
||||||
const lastUpdated = result.last_updated || new Date();
|
const repoOwner = result.repo_owner || '';
|
||||||
const repoName = namespace ? `${namespace}/${name}` : name;
|
const repoName = name;
|
||||||
const officialBadge = result.is_official ? '<span class="badge badge-official">官方</span>' : '';
|
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>' : '';
|
const automatedBadge = result.is_automated ? '<span class="badge badge-automated">自动构建</span>' : '';
|
||||||
|
|
||||||
console.log('处理仓库:', {
|
console.log('处理仓库:', {
|
||||||
name,
|
name,
|
||||||
namespace,
|
repoOwner,
|
||||||
repoName,
|
repoName,
|
||||||
isOfficial: result.is_official,
|
isOfficial: result.is_official,
|
||||||
organization: result.organization
|
isAutomated: result.is_automated
|
||||||
});
|
});
|
||||||
|
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<div class="result-title">
|
<div class="result-title">
|
||||||
${repoName}
|
${repoName}
|
||||||
${officialBadge}
|
${officialBadge}
|
||||||
${orgBadge}
|
|
||||||
${automatedBadge}
|
|
||||||
</div>
|
</div>
|
||||||
<div class="result-description">${description}</div>
|
<div class="result-description">${description}</div>
|
||||||
<div class="result-meta">
|
<div class="result-meta">
|
||||||
@@ -606,14 +602,14 @@
|
|||||||
${starCount > 0 ? `<span class="meta-item">⭐ ${formatNumber(starCount)}</span>` : ''}
|
${starCount > 0 ? `<span class="meta-item">⭐ ${formatNumber(starCount)}</span>` : ''}
|
||||||
${pullCount > 0 ? `<span class="meta-item">⬇️ ${formatNumber(pullCount)}</span>` : ''}
|
${pullCount > 0 ? `<span class="meta-item">⬇️ ${formatNumber(pullCount)}</span>` : ''}
|
||||||
</span>
|
</span>
|
||||||
<span class="meta-item">更新于 ${formatTimeAgo(lastUpdated)}</span>
|
<span class="meta-item">更新于 ${formatTimeAgo(result.last_updated)}</span>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
card.addEventListener('click', () => {
|
card.addEventListener('click', () => {
|
||||||
console.log('点击仓库:', name, namespace);
|
console.log('点击仓库:', name, repoOwner);
|
||||||
currentRepo = result;
|
currentRepo = result;
|
||||||
loadTags(namespace || 'library', name);
|
loadTags(repoOwner, name);
|
||||||
});
|
});
|
||||||
|
|
||||||
resultsContainer.appendChild(card);
|
resultsContainer.appendChild(card);
|
||||||
@@ -657,8 +653,6 @@
|
|||||||
<div class="tag-title">
|
<div class="tag-title">
|
||||||
${repoName}
|
${repoName}
|
||||||
${currentRepo.is_official ? '<span class="badge badge-official">官方</span>' : ''}
|
${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>
|
||||||
<div class="tag-description">${currentRepo.description || '暂无描述'}</div>
|
<div class="tag-description">${currentRepo.description || '暂无描述'}</div>
|
||||||
<div class="tag-meta">
|
<div class="tag-meta">
|
||||||
|
|||||||
@@ -24,16 +24,13 @@ type SearchResult struct {
|
|||||||
|
|
||||||
// Repository 仓库信息
|
// Repository 仓库信息
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"repo_name"`
|
||||||
Namespace string `json:"namespace"`
|
Description string `json:"short_description"`
|
||||||
Description string `json:"description"`
|
|
||||||
IsOfficial bool `json:"is_official"`
|
IsOfficial bool `json:"is_official"`
|
||||||
IsAutomated bool `json:"is_automated"`
|
IsAutomated bool `json:"is_automated"`
|
||||||
StarCount int `json:"star_count"`
|
StarCount int `json:"star_count"`
|
||||||
PullCount int `json:"pull_count"`
|
PullCount int `json:"pull_count"`
|
||||||
LastUpdated time.Time `json:"last_updated"`
|
RepoOwner string `json:"repo_owner"`
|
||||||
Status int `json:"status"`
|
|
||||||
Organization string `json:"organization,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TagInfo 标签信息
|
// TagInfo 标签信息
|
||||||
@@ -269,6 +266,13 @@ func RegisterSearchRoute(r *gin.Engine) {
|
|||||||
return
|
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)
|
c.JSON(http.StatusOK, result)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user