Files
fish03andClaude Opus 5.5 bef9f8b4ed Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 14:43:16 +07:00

65 lines
1.6 KiB
Go

package playletser
import (
"strconv"
"strings"
)
func recommendPageURL(themeID int64, themeSlug string, pageNum int) string {
if pageNum <= 0 {
pageNum = 1
}
path := "/topic"
if segment := pathSegment(themeSlug, themeID); segment != "" {
path += "/" + segment
}
if pageNum > 1 {
path += "/page/" + strconv.Itoa(pageNum)
}
return path + "/"
}
func RecommendPagePath(q RecommendQuery) string {
q.Normalize()
return recommendPageURL(q.ThemeID, q.ThemeSlug, q.PageNum)
}
// RecommendThemeTitle 专题页标题:优先题材名称,其次使用列表接口 SEO 标题。
func RecommendThemeTitle(name, seoTitle string, themeID int64) string {
name = strings.TrimSpace(name)
if name != "" {
return name
}
seoTitle = strings.TrimSpace(seoTitle)
if seoTitle != "" {
return seoTitle
}
if themeID > 0 {
return "专题短剧"
}
return "专题推荐"
}
// RecommendCanonicalPath 推荐页 canonical(不含 page)。
func RecommendCanonicalPath(themeID int64, themeSlug string) string {
return recommendPageURL(themeID, themeSlug, 1)
}
// BuildRecommendPagination 推荐列表分页。
func BuildRecommendPagination(q RecommendQuery, totalCount int64) PaginationVM {
q.Normalize()
return BuildPagination(func(p int) string {
return recommendPageURL(q.ThemeID, q.ThemeSlug, p)
}, q.PageNum, q.PageSize, totalCount)
}
// ParseRecommendQuery 从路由解析分页。
func ParseRecommendQuery(pageStr string) RecommendQuery {
q := RecommendQuery{PageSize: defaultRecommendSize, SortOrder: sortHeat}
if n, err := strconv.Atoi(strings.TrimSpace(pageStr)); err == nil {
q.PageNum = n
}
q.Normalize()
return q
}