Skip to content

Commit 0b5db5b

Browse files
author
yszl
committed
feat(界面): 为视频卡片添加集数显示功能
在视频卡片和标题前添加集数标签,使用模板函数提取标题中的集数 添加CSS样式美化集数标签显示
1 parent 97eb00e commit 0b5db5b

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,11 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
563563
return seriesVideos[i].CreatedAt.Before(seriesVideos[j].CreatedAt)
564564
})
565565

566-
tmpl, err := template.ParseFiles("templates/index.html")
566+
funcMap := template.FuncMap{
567+
"episodeNum": extractEpisodeNumber,
568+
}
569+
570+
tmpl, err := template.New("index.html").Funcs(funcMap).ParseFiles("templates/index.html")
567571
if err != nil {
568572
http.Error(w, err.Error(), http.StatusInternalServerError)
569573
return

static/style.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,31 @@ h1 {
5353
border-radius: 8px;
5454
margin-bottom: 15px;
5555
overflow: hidden;
56+
position: relative;
57+
}
58+
59+
.episode-badge-thumb {
60+
position: absolute;
61+
top: 0;
62+
right: 0;
63+
background-color: rgba(187, 134, 252, 0.9);
64+
color: black;
65+
padding: 4px 8px;
66+
border-bottom-left-radius: 8px;
67+
font-weight: bold;
68+
font-size: 1rem;
69+
z-index: 5;
70+
}
71+
72+
.episode-tag {
73+
display: inline-block;
74+
background-color: #bb86fc;
75+
color: black;
76+
padding: 2px 6px;
77+
border-radius: 4px;
78+
font-size: 0.8em;
79+
margin-right: 8px;
80+
vertical-align: middle;
5681
}
5782

5883
.video-thumbnail video {

templates/index.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,17 @@ <h1>
6161
{{range .Videos}}
6262
<a href="/play?id={{.ID}}" class="video-card" tabindex="0">
6363
<div class="video-thumbnail">
64+
{{$ep := episodeNum .Title}}
65+
{{if gt $ep 0}}
66+
<div class="episode-badge-thumb">{{printf "%02d" $ep}}</div>
67+
{{end}}
6468
<video src="{{.Path}}" preload="metadata"></video>
6569
</div>
6670
<div class="video-info">
67-
<h2>{{.Title}}</h2>
71+
<h2>
72+
{{if gt $ep 0}}<span class="episode-tag">{{printf "%02d" $ep}}</span>{{end}}
73+
{{.Title}}
74+
</h2>
6875
<p>
6976
<span class="status-badge {{.Status}}" id="status-{{.ID}}">{{.Status}}</span>
7077
{{.CreatedAt.Format "2006-01-02 15:04"}}

0 commit comments

Comments
 (0)