Files
谢宇宁andClaude Opus 5.5 0fbdba5ccf Initial commit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 11:47:47 +07:00

181 lines
3.5 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package playletser
import (
"fmt"
"net/url"
"strconv"
"strings"
)
// pathSegment 生成路径段:优先 slug,没有 slug 时才用 id。
func pathSegment(slug string, id int64) string {
slug = strings.TrimSpace(slug)
if slug != "" {
return url.PathEscape(slug)
}
if id > 0 {
return strconv.FormatInt(id, 10)
}
return ""
}
// SearchResultsURL 搜索结果页路径:/search/{q}/(对应 search.html)
func SearchResultsURL(q string) string {
q = strings.TrimSpace(q)
if q == "" {
return "/search"
}
return "/search/" + url.PathEscape(q)
}
func detailURL(slug string, id int64) string {
if segment := pathSegment(slug, id); segment != "" {
return "/play/" + segment
}
return "#"
}
func playURL(slug string, playletID int64) string {
return chapterPlayURL(slug, playletID, 0)
}
func chapterPlayURL(slug string, playletID, chapterID int64) string {
segment := pathSegment(slug, playletID)
if segment == "" {
return "#"
}
if chapterID <= 0 {
return "/play/" + segment
}
return fmt.Sprintf("/play/%s/%d", segment, chapterID)
}
func categoryURL(slug string, id int64) string {
if segment := pathSegment(slug, id); segment != "" {
return "/topic-detail/" + segment
}
return "/topic"
}
func DetailPath(slug string, id int64) string {
return detailURL(slug, id)
}
func PlayPath(slug string, id int64) string {
return playURL(slug, id)
}
func ChapterPlayPath(slug string, playletID, chapterID int64) string {
return chapterPlayURL(slug, playletID, chapterID)
}
func updateStatusText(status int) string {
if status == 2 {
return "已完结"
}
return "连载中"
}
func browseText(n int64) string {
if n <= 0 {
return "0次播放"
}
if n < 10000 {
return fmt.Sprintf("%d次播放", n)
}
v := float64(n) / 10000
if v >= 100 {
return fmt.Sprintf("%.0f万次播放", v)
}
return fmt.Sprintf("%.1f万次播放", v)
}
func usableAnchor(anchor string) string {
anchor = strings.TrimSpace(anchor)
if anchor == "" || anchor == "暂无" {
return ""
}
return anchor
}
func rankClass(rank int) string {
switch rank {
case 1:
return "gold"
case 2:
return "silver"
case 3:
return "bronze"
default:
return "dark"
}
}
func episodeText(n int) string {
if n <= 0 {
return ""
}
return fmt.Sprintf("%d集", n)
}
func formatHeat(n int64) string {
if n <= 0 {
return "0 热度"
}
if n < 10000 {
return fmt.Sprintf("%d 热度", n)
}
v := float64(n) / 10000
if v >= 100 {
return fmt.Sprintf("%.0f万 热度", v)
}
return fmt.Sprintf("%.1f万 热度", v)
}
func formatMediaTime(sec int) string {
if sec <= 0 {
return "00:00"
}
h := sec / 3600
m := (sec % 3600) / 60
s := sec % 60
if h > 0 {
return fmt.Sprintf("%02d:%02d:%02d", h, m, s)
}
return fmt.Sprintf("%02d:%02d", m, s)
}
// playletDisplayName 优先 playName,其次 title。
func playletDisplayName(playName, title string) string {
return firstNonEmpty(playName, title)
}
// PlayletDisplayName 对外导出的剧名展示。
func PlayletDisplayName(playName, title string) string {
return playletDisplayName(playName, title)
}
// formatLikeCount 封面点赞数展示:不足一万原样,否则 x.x 万。
func formatLikeCount(n int64) string {
if n <= 0 {
return "0"
}
if n < 10000 {
return fmt.Sprintf("%d", n)
}
v := float64(n) / 10000
if v >= 100 {
return fmt.Sprintf("%.0f 万", v)
}
return fmt.Sprintf("%.1f 万", v)
}
func firstNonEmpty(values ...string) string {
for _, v := range values {
if strings.TrimSpace(v) != "" {
return v
}
}
return ""
}