优化搜索结果
This commit is contained in:
@@ -106,16 +106,18 @@
|
|||||||
font-size: 1.2rem;
|
font-size: 1.2rem;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
color: #39c5bc;
|
color: #0091e2;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.result-description {
|
.result-description {
|
||||||
color: var(--fontcolor);
|
color: var(--fontcolor);
|
||||||
margin-bottom: 15px;
|
margin: 10px 0;
|
||||||
font-size: 0.9rem;
|
font-size: 0.95rem;
|
||||||
|
line-height: 1.5;
|
||||||
}
|
}
|
||||||
|
|
||||||
.result-meta {
|
.result-meta {
|
||||||
@@ -125,6 +127,47 @@
|
|||||||
font-size: 0.9rem;
|
font-size: 0.9rem;
|
||||||
color: var(--fontcolor);
|
color: var(--fontcolor);
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
|
margin-top: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-stats {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-pulls {
|
||||||
|
font-size: 0.85rem;
|
||||||
|
color: #666;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge {
|
||||||
|
padding: 4px 8px;
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
font-weight: normal;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-official {
|
||||||
|
background-color: #28a745;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-organization {
|
||||||
|
background-color: #6c757d;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.badge-automated {
|
||||||
|
background-color: #17a2b8;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
.meta-item {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.back-button {
|
.back-button {
|
||||||
@@ -211,23 +254,6 @@
|
|||||||
background-color: #2ea8a0;
|
background-color: #2ea8a0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.badge {
|
|
||||||
padding: 4px 8px;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
font-weight: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
.badge-official {
|
|
||||||
background-color: #39c5bc;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.badge-organization {
|
|
||||||
background-color: #6c757d;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-list {
|
.tag-list {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
display: none;
|
display: none;
|
||||||
@@ -352,45 +378,6 @@
|
|||||||
.back-to-search:hover {
|
.back-to-search:hover {
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
.meta-item {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
margin-right: 15px;
|
|
||||||
color: var(--fontcolor);
|
|
||||||
opacity: 0.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.badge-automated {
|
|
||||||
background-color: #28a745;
|
|
||||||
color: white;
|
|
||||||
margin-left: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tag-meta {
|
|
||||||
display: flex;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
gap: 15px;
|
|
||||||
margin: 10px 0;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
color: var(--fontcolor);
|
|
||||||
opacity: 0.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.vulnerability-indicator {
|
|
||||||
display: inline-flex;
|
|
||||||
align-items: center;
|
|
||||||
gap: 5px;
|
|
||||||
margin-left: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.arch-item {
|
|
||||||
background-color: var(--inputcolor);
|
|
||||||
padding: 5px 10px;
|
|
||||||
border-radius: 5px;
|
|
||||||
font-size: 0.8rem;
|
|
||||||
cursor: help;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -546,16 +533,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatTimeAgo(dateString) {
|
function formatTimeAgo(dateString) {
|
||||||
|
if (!dateString) return '未知时间';
|
||||||
|
|
||||||
const date = new Date(dateString);
|
const date = new Date(dateString);
|
||||||
|
if (isNaN(date.getTime())) return '未知时间';
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const diffTime = Math.abs(now - date);
|
const diffTime = Math.abs(now - date);
|
||||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
|
const diffMinutes = Math.floor(diffTime / (1000 * 60));
|
||||||
|
const diffHours = Math.floor(diffTime / (1000 * 60 * 60));
|
||||||
|
const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
|
||||||
|
const diffMonths = Math.floor(diffDays / 30);
|
||||||
|
const diffYears = Math.floor(diffDays / 365);
|
||||||
|
|
||||||
if (diffDays === 1) return '昨天';
|
if (diffMinutes < 60) return `${diffMinutes}分钟前`;
|
||||||
|
if (diffHours < 24) return `${diffHours}小时前`;
|
||||||
if (diffDays < 7) return `${diffDays}天前`;
|
if (diffDays < 7) return `${diffDays}天前`;
|
||||||
if (diffDays < 30) return `${Math.floor(diffDays / 7)}周前`;
|
if (diffDays < 30) return `${Math.floor(diffDays / 7)}周前`;
|
||||||
if (diffDays < 365) return `${Math.floor(diffDays / 30)}个月前`;
|
if (diffMonths < 12) return `${diffMonths}个月前`;
|
||||||
return `${Math.floor(diffDays / 365)}年前`;
|
return `${diffYears}年前`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayResults(results) {
|
function displayResults(results) {
|
||||||
@@ -567,49 +563,50 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('显示搜索结果:', results);
|
|
||||||
|
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
const card = document.createElement('div');
|
const card = document.createElement('div');
|
||||||
card.className = 'result-card';
|
card.className = 'result-card';
|
||||||
|
|
||||||
// 确保所有字段都有值
|
|
||||||
const name = result.repo_name || '';
|
const name = result.repo_name || '';
|
||||||
const description = result.short_description || '暂无描述';
|
const description = result.short_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 repoOwner = result.repo_owner || '';
|
const pullsLastWeek = result.pulls_last_week || 0;
|
||||||
const repoName = name;
|
const lastUpdated = result.last_updated || '';
|
||||||
const officialBadge = result.is_official ? '<span class="badge badge-official">官方</span>' : '';
|
const organization = result.affiliation || '';
|
||||||
const automatedBadge = result.is_automated ? '<span class="badge badge-automated">自动构建</span>' : '';
|
|
||||||
|
|
||||||
console.log('处理仓库:', {
|
const badges = [];
|
||||||
name,
|
if (result.is_official) badges.push('<span class="badge badge-official">官方</span>');
|
||||||
repoOwner,
|
if (organization) badges.push(`<span class="badge badge-organization">By ${organization}</span>`);
|
||||||
repoName,
|
if (result.is_automated) badges.push('<span class="badge badge-automated">自动构建</span>');
|
||||||
isOfficial: result.is_official,
|
|
||||||
isAutomated: result.is_automated
|
const stats = [];
|
||||||
});
|
if (pullCount > 0) stats.push(`${formatNumber(pullCount)}+`);
|
||||||
|
if (starCount > 0) stats.push(`${formatNumber(starCount)}`);
|
||||||
|
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<div class="result-title">
|
<div class="result-title">
|
||||||
${repoName}
|
${name}
|
||||||
${officialBadge}
|
${badges.join(' ')}
|
||||||
</div>
|
</div>
|
||||||
<div class="result-description">${description}</div>
|
<div class="result-description">${description}</div>
|
||||||
<div class="result-meta">
|
<div class="result-meta">
|
||||||
<span>
|
<div class="meta-stats">
|
||||||
${starCount > 0 ? `<span class="meta-item">⭐ ${formatNumber(starCount)}</span>` : ''}
|
${stats.length > 0 ? `<span class="meta-item">${stats.join(' • ')}</span>` : ''}
|
||||||
${pullCount > 0 ? `<span class="meta-item">⬇️ ${formatNumber(pullCount)}</span>` : ''}
|
${lastUpdated ? `<span class="meta-item">更新于 ${formatTimeAgo(lastUpdated)}</span>` : ''}
|
||||||
</span>
|
</div>
|
||||||
<span class="meta-item">更新于 ${formatTimeAgo(result.last_updated)}</span>
|
${pullsLastWeek > 0 ? `
|
||||||
|
<div class="meta-pulls">
|
||||||
|
<span class="meta-item">本周拉取: ${formatNumber(pullsLastWeek)}</span>
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
card.addEventListener('click', () => {
|
card.addEventListener('click', () => {
|
||||||
console.log('点击仓库:', name, repoOwner);
|
console.log('点击仓库:', name);
|
||||||
currentRepo = result;
|
currentRepo = result;
|
||||||
loadTags(repoOwner, name);
|
loadTags(result.is_official ? 'library' : (result.repo_owner || ''), name);
|
||||||
});
|
});
|
||||||
|
|
||||||
resultsContainer.appendChild(card);
|
resultsContainer.appendChild(card);
|
||||||
|
|||||||
@@ -31,6 +31,10 @@ type Repository struct {
|
|||||||
StarCount int `json:"star_count"`
|
StarCount int `json:"star_count"`
|
||||||
PullCount int `json:"pull_count"`
|
PullCount int `json:"pull_count"`
|
||||||
RepoOwner string `json:"repo_owner"`
|
RepoOwner string `json:"repo_owner"`
|
||||||
|
LastUpdated string `json:"last_updated"`
|
||||||
|
Status int `json:"status"`
|
||||||
|
Organization string `json:"affiliation"`
|
||||||
|
PullsLastWeek int `json:"pulls_last_week"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TagInfo 标签信息
|
// TagInfo 标签信息
|
||||||
|
|||||||
Reference in New Issue
Block a user