133 lines
3.1 KiB
Go
133 lines
3.1 KiB
Go
// Package h5path 统一拼装熟果短剧 H5 的页面路径。
|
|
// Abs 与 SitemapAbs 都与线上路由一致:首页保留尾斜杠,其余页面不带尾斜杠。
|
|
package h5path
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
"videoweb/pub/common/utils"
|
|
)
|
|
|
|
func Segment(slug string, id int64) string {
|
|
return utils.PathSegment(slug, id)
|
|
}
|
|
|
|
// Entity 拼 /{prefix}/{slug|id},无有效段时只返回 prefix。
|
|
func Entity(prefix, slug string, id int64) string {
|
|
prefix = "/" + strings.Trim(prefix, "/")
|
|
if segment := Segment(slug, id); segment != "" {
|
|
return prefix + "/" + segment
|
|
}
|
|
return prefix
|
|
}
|
|
|
|
func Playlet(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/play", slug, id)
|
|
}
|
|
|
|
// Drama 短剧详情页:/drama/{slug|id}。
|
|
func Drama(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/drama", slug, id)
|
|
}
|
|
|
|
func PlayletChapter(slug string, playletID, chapterID int64) string {
|
|
base := Playlet(slug, playletID)
|
|
if base == "" || chapterID <= 0 {
|
|
return ""
|
|
}
|
|
return base + "/" + strconv.FormatInt(chapterID, 10)
|
|
}
|
|
|
|
func TopicDetail(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return "/topic"
|
|
}
|
|
return Entity("/topic-detail", slug, id)
|
|
}
|
|
|
|
func Tag(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/tags", slug, id)
|
|
}
|
|
|
|
func ListTheme(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return "/list"
|
|
}
|
|
return Entity("/list", slug, id)
|
|
}
|
|
|
|
func VideoPlay(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/series-play", slug, id)
|
|
}
|
|
|
|
func MoreList(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/more-list", slug, id)
|
|
}
|
|
|
|
func MoreSeriesList(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/more-series-list", slug, id)
|
|
}
|
|
|
|
// Topic 专题详情:/topics/{slug|id}。
|
|
func Topic(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/topics", slug, id)
|
|
}
|
|
|
|
// TopicTag 标签列表:/topics/tag/{slug|id}。
|
|
func TopicTag(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/topics/tag", slug, id)
|
|
}
|
|
|
|
// ShortsMore 首页模块更多列表:/shorts/more/{slug|id}。
|
|
func ShortsMore(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity("/shorts/more", slug, id)
|
|
}
|
|
|
|
func SeriesTopic(topicID int64) string {
|
|
if topicID <= 0 {
|
|
return "/series"
|
|
}
|
|
return "/series/all/" + strconv.FormatInt(topicID, 10) + "/1"
|
|
}
|
|
|
|
// Abs 拼绝对地址。首页保留尾斜杠,其余页面与 H5 路由一致、不带尾斜杠。
|
|
func Abs(webAddr, path string) string {
|
|
path = strings.TrimSpace(path)
|
|
if path == "" || path == "/" {
|
|
return utils.JoinUrlPathKeepSlash(webAddr, "/")
|
|
}
|
|
return utils.JoinUrlPathKeepSlash(webAddr, "/"+strings.Trim(path, "/"))
|
|
}
|
|
|
|
// SitemapAbs 拼 sitemap 页面绝对地址,与线上 H5 路由一致:首页保留尾斜杠,其余不带。
|
|
func SitemapAbs(webAddr, path string) string {
|
|
return Abs(webAddr, path)
|
|
}
|