Skip to content

Commit b9a755f

Browse files
committed
Refactor: 首页聚合改造,AI/Tech 统一时间排序展示
- 首页文章列表混合 site.posts + site.ai 按时间倒序 - 每篇卡片标题前加栏目 badge(AI / Tech) - 侧边栏 Archives 改名为 Tech,AI 图标换为 fa-robot - 移除右侧「最近更新」面板(首页已是全站聚合视图) - 新增 _data/locales/zh-CN.yml 覆盖 tab 显示名
1 parent a608308 commit b9a755f

6 files changed

Lines changed: 155 additions & 3 deletions

File tree

_data/locales/zh-CN.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tabs:
2+
tech: Tech

_includes/update-list.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<!-- Intentionally empty: recent updates are shown inline on the homepage -->

_layouts/home.html

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
---
2+
layout: default
3+
refactor: true
4+
---
5+
6+
{% include lang.html %}
7+
8+
<!-- Build merged list: site.posts + site.ai, sorted by date desc -->
9+
{% assign all_items = '' | split: '' %}
10+
11+
{% for post in site.posts %}
12+
{% unless post.hidden %}
13+
{% capture elem %}{{ post.date | date: "%Y%m%d%H%M%S" }}::posts::{{ forloop.index0 }}{% endcapture %}
14+
{% assign all_items = all_items | push: elem %}
15+
{% endunless %}
16+
{% endfor %}
17+
18+
{% for doc in site.ai %}
19+
{% capture elem %}{{ doc.date | date: "%Y%m%d%H%M%S" }}::ai::{{ forloop.index0 }}{% endcapture %}
20+
{% assign all_items = all_items | push: elem %}
21+
{% endfor %}
22+
23+
{% assign all_items = all_items | sort | reverse %}
24+
25+
<!-- Manual pagination using paginator's page info -->
26+
{% assign per_page = paginator.per_page %}
27+
{% assign page_num = paginator.page %}
28+
{% assign skip = page_num | minus: 1 | times: per_page %}
29+
30+
<div id="post-list" class="flex-grow-1 px-xl-1">
31+
{% for item in all_items limit: per_page offset: skip %}
32+
{% assign parts = item | split: '::' %}
33+
{% assign col = parts[1] %}
34+
{% assign index = parts[2] | plus: 0 %}
35+
36+
{% if col == 'posts' %}
37+
{% assign post = site.posts[index] %}
38+
{% assign badge_class = 'post-badge--tech' %}
39+
{% assign badge_text = 'Tech' %}
40+
{% else %}
41+
{% assign post = site.ai[index] %}
42+
{% assign badge_class = 'post-badge--ai' %}
43+
{% assign badge_text = 'AI' %}
44+
{% endif %}
45+
46+
<article class="card-wrapper card">
47+
<a href="{{ post.url | relative_url }}" class="post-preview row g-0 flex-md-row-reverse">
48+
{% assign card_body_col = '12' %}
49+
50+
{% if post.image %}
51+
{% assign src = post.image.path | default: post.image %}
52+
{% unless src contains '//' %}
53+
{% assign src = post.img_path | append: '/' | append: src | replace: '//', '/' %}
54+
{% endunless %}
55+
56+
{% assign alt = post.image.alt | xml_escape | default: 'Preview Image' %}
57+
58+
{% assign lqip = null %}
59+
60+
{% if post.image.lqip %}
61+
{% capture lqip %}lqip="{{ post.image.lqip }}"{% endcapture %}
62+
{% endif %}
63+
64+
<div class="col-md-5">
65+
<img src="{{ src }}" alt="{{ alt }}" {{ lqip }}>
66+
</div>
67+
68+
{% assign card_body_col = '7' %}
69+
{% endif %}
70+
71+
<div class="col-md-{{ card_body_col }}">
72+
<div class="card-body d-flex flex-column">
73+
<h1 class="card-title my-2 mt-md-0">
74+
<span class="post-badge {{ badge_class }}">{{ badge_text }}</span>
75+
{{ post.title }}
76+
</h1>
77+
78+
<div class="card-text content mt-0 mb-3">
79+
<p>
80+
{% include no-linenos.html content=post.content %}
81+
{{ content | markdownify | strip_html | truncate: 200 | escape }}
82+
</p>
83+
</div>
84+
85+
<div class="post-meta flex-grow-1 d-flex align-items-end">
86+
<div class="me-auto">
87+
<!-- posted date -->
88+
<i class="far fa-calendar fa-fw me-1"></i>
89+
{% include datetime.html date=post.date lang=lang %}
90+
91+
<!-- categories -->
92+
{% if post.categories.size > 0 %}
93+
<i class="far fa-folder-open fa-fw me-1"></i>
94+
<span class="categories">
95+
{% for category in post.categories %}
96+
{{ category }}
97+
{%- unless forloop.last -%},{%- endunless -%}
98+
{% endfor %}
99+
</span>
100+
{% endif %}
101+
</div>
102+
103+
{% if post.pin %}
104+
<div class="pin ms-1">
105+
<i class="fas fa-thumbtack fa-fw"></i>
106+
<span>{{ site.data.locales[lang].post.pin_prompt }}</span>
107+
</div>
108+
{% endif %}
109+
</div>
110+
<!-- .post-meta -->
111+
</div>
112+
<!-- .card-body -->
113+
</div>
114+
</a>
115+
</article>
116+
{% endfor %}
117+
</div>
118+
<!-- #post-list -->
119+
120+
{% if paginator.total_pages > 1 %}
121+
{% include post-paginator.html %}
122+
{% endif %}

_tabs/ai.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: custom-collection
3-
title: ai
4-
icon: fas fa-charging-station
3+
title: AI
4+
icon: fas fa-robot
55
order: 3.04
66
---
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
22
layout: archives
3-
icon: fas fa-archive
3+
icon: fas fa-code
44
order: 3
55
---
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
---
3+
4+
@import 'main';
5+
6+
/* append your custom style below */
7+
8+
.post-badge {
9+
display: inline-block;
10+
font-size: 0.7rem;
11+
font-weight: 600;
12+
padding: 0.1em 0.5em;
13+
border-radius: 0.75em;
14+
margin-right: 0.5rem;
15+
vertical-align: middle;
16+
letter-spacing: 0.03em;
17+
}
18+
19+
.post-badge--ai {
20+
color: var(--link-color);
21+
border: 1px solid var(--link-color);
22+
}
23+
24+
.post-badge--tech {
25+
color: var(--text-muted-color);
26+
border: 1px solid var(--text-muted-color);
27+
}

0 commit comments

Comments
 (0)