feat: 添加热门工具排行榜功能
v2.5.0 - 新增首页热门工具展示 新增功能: - 在首页顶部展示按浏览量排序的前10个热门工具 - 响应式网格布局(桌面5列、平板3列、手机2列) - 视觉突出的排行榜徽章和排名标识(前三名金银铜色) - 仅在首页显示,筛选和搜索时隐藏 技术实现: - app.py: 添加popular_sites查询逻辑 - templates/index_new.html: 新增热门工具展示区域和样式 用户体验提升: - 帮助用户快速发现最受欢迎的AI工具 - 视觉层级清晰,排名一目了然 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
7
app.py
7
app.py
@@ -130,9 +130,14 @@ def create_app(config_name='default'):
|
||||
pagination = query.paginate(page=page, per_page=per_page, error_out=False)
|
||||
sites = pagination.items
|
||||
|
||||
# 获取热门工具(按浏览次数排序,最多10个)
|
||||
popular_sites = Site.query.filter_by(is_active=True)\
|
||||
.order_by(Site.view_count.desc()).limit(10).all()
|
||||
|
||||
return render_template('index_new.html', sites=sites, tags=tags,
|
||||
selected_tag=selected_tag, search_query=search_query,
|
||||
pagination=pagination, tag_counts=tag_counts)
|
||||
pagination=pagination, tag_counts=tag_counts,
|
||||
popular_sites=popular_sites)
|
||||
|
||||
@app.route('/site/<code>')
|
||||
def site_detail(code):
|
||||
|
||||
@@ -44,6 +44,126 @@
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
/* 热门工具排行榜 */
|
||||
.popular-section {
|
||||
padding: 0 0 32px 0;
|
||||
}
|
||||
|
||||
.popular-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.popular-title {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
color: var(--text-primary);
|
||||
margin: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.popular-badge {
|
||||
background: linear-gradient(135deg, #ff6b6b 0%, #ff8e53 100%);
|
||||
color: white;
|
||||
font-size: 18px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.popular-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.popular-item {
|
||||
background: var(--bg-white);
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
text-decoration: none;
|
||||
transition: all 0.3s;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.popular-item:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
||||
border-color: var(--primary-blue);
|
||||
}
|
||||
|
||||
.popular-rank {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
left: 8px;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
|
||||
color: #b8860b;
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.popular-rank.rank-2 {
|
||||
background: linear-gradient(135deg, #c0c0c0 0%, #e8e8e8 100%);
|
||||
color: #696969;
|
||||
}
|
||||
|
||||
.popular-rank.rank-3 {
|
||||
background: linear-gradient(135deg, #cd7f32 0%, #e9a76f 100%);
|
||||
color: #654321;
|
||||
}
|
||||
|
||||
.popular-rank.rank-other {
|
||||
background: #f1f5f9;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.popular-logo {
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 12px;
|
||||
object-fit: cover;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.popular-name {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--text-primary);
|
||||
margin-bottom: 4px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.popular-views {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: #94a3b8;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.popular-fire {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
/* 分类过滤 */
|
||||
.categories {
|
||||
padding: 32px 0;
|
||||
@@ -342,10 +462,26 @@
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
.popular-grid {
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.popular-logo {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
}
|
||||
|
||||
.tools-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
|
||||
@media (min-width: 769px) and (max-width: 1024px) {
|
||||
.popular-grid {
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
@@ -361,6 +497,37 @@
|
||||
|
||||
<div class="main-content">
|
||||
|
||||
<!-- 热门工具排行榜 -->
|
||||
{% if popular_sites and not selected_tag and not search_query %}
|
||||
<div class="popular-section">
|
||||
<div class="popular-header">
|
||||
<h2 class="popular-title">
|
||||
<span class="popular-badge">🔥</span>
|
||||
热门工具排行榜
|
||||
</h2>
|
||||
</div>
|
||||
<div class="popular-grid">
|
||||
{% for site in popular_sites[:10] %}
|
||||
<a href="/site/{{ site.code }}" class="popular-item">
|
||||
<div class="popular-rank {% if loop.index == 1 %}rank-1{% elif loop.index == 2 %}rank-2{% elif loop.index == 3 %}rank-3{% else %}rank-other{% endif %}">
|
||||
{{ loop.index }}
|
||||
</div>
|
||||
{% if site.logo %}
|
||||
<img src="{{ site.logo }}" alt="{{ site.name }}" class="popular-logo">
|
||||
{% else %}
|
||||
<div class="popular-logo" style="background: linear-gradient(135deg, #0ea5e9 0%, #8b5cf6 100%);"></div>
|
||||
{% endif %}
|
||||
<div class="popular-name">{{ site.name }}</div>
|
||||
<div class="popular-views">
|
||||
<span class="popular-fire">👁</span>
|
||||
<span>{% if site.view_count >= 1000 %}{{ (site.view_count / 1000) | round(1) }}k{% else %}{{ site.view_count | default(0) }}{% endif %}</span>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- 分类过滤 -->
|
||||
<div class="categories" id="categories">
|
||||
<div class="category-tabs" id="categoryTabs">
|
||||
|
||||
Reference in New Issue
Block a user