@@ -0,0 +1,122 @@
|
||||
// Package h5path 统一拼装黄豆 H5(91dj-h5)的页面路径。
|
||||
// 页面地址与线上 canonical 一致,不追加尾斜杠。
|
||||
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("/short-drama", slug, id)
|
||||
}
|
||||
|
||||
// PlayletPlay 播放页:/short-drama/{slug}/play/{集数}。集数是 CurrentEpisode,不是剧集文档 id。
|
||||
func PlayletPlay(slug string, id, episode int64) string {
|
||||
base := Playlet(slug, id)
|
||||
if base == "" || episode <= 0 {
|
||||
return ""
|
||||
}
|
||||
return base + "/play/" + strconv.FormatInt(episode, 10)
|
||||
}
|
||||
|
||||
func PlayletChapter(slug string, playletID, episode int64) string {
|
||||
return PlayletPlay(slug, playletID, episode)
|
||||
}
|
||||
|
||||
func TopicDetail(slug string, id int64) string {
|
||||
if isReservedTopicSlug(slug) {
|
||||
slug = ""
|
||||
}
|
||||
if Segment(slug, id) == "" {
|
||||
return "/topics"
|
||||
}
|
||||
return Entity("/topics", slug, id)
|
||||
}
|
||||
|
||||
func Tag(slug string, id int64) string {
|
||||
if Segment(slug, id) == "" {
|
||||
return ""
|
||||
}
|
||||
return Entity("/topics/tag", slug, id)
|
||||
}
|
||||
|
||||
func ListTheme(slug string, id int64) string {
|
||||
return TopicDetail(slug, id)
|
||||
}
|
||||
|
||||
func isReservedTopicSlug(slug string) bool {
|
||||
switch strings.ToLower(strings.TrimSpace(slug)) {
|
||||
case "tag", "page":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
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("/shorts/more", slug, id)
|
||||
}
|
||||
|
||||
func MoreSeriesList(slug string, id int64) string {
|
||||
if Segment(slug, id) == "" {
|
||||
return ""
|
||||
}
|
||||
return Entity("/more-series-list", 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 canonical 一致,不追加尾斜杠。
|
||||
func SitemapAbs(webAddr, path string) string {
|
||||
webAddr = strings.TrimRight(strings.TrimSpace(webAddr), "/")
|
||||
path = strings.TrimSpace(path)
|
||||
if webAddr == "" {
|
||||
return ""
|
||||
}
|
||||
if path == "" || path == "/" {
|
||||
return webAddr
|
||||
}
|
||||
return webAddr + "/" + strings.Trim(path, "/")
|
||||
}
|
||||
Reference in New Issue
Block a user