来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83 项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet 测试目录 /server/hkdj_net,App/Web API 30331/30332 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
124 lines
3.2 KiB
Go
124 lines
3.2 KiB
Go
// Package h5path 统一拼装花魁 NET H5 的页面路径。
|
|
// Abs 保持原有无尾斜杠规范,SitemapAbs 专用于 sitemap 页面 URL
|
|
package h5path
|
|
|
|
import (
|
|
"hkdj-web-server/pub/common/utils"
|
|
"net/url"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// Public page prefixes shared by sitemap, API canonical metadata and SEO push.
|
|
const (
|
|
DramaListPath = "/dramas"
|
|
DramaPath = "/drama"
|
|
CollectionsPath = "/collections"
|
|
CollectionPath = "/collection"
|
|
SeriesPath = "/series"
|
|
SeriesWatchPath = "/series/watch"
|
|
TagsPath = "/tags"
|
|
CuratedDramasPath = "/curated/dramas"
|
|
CuratedSeriesPath = "/curated/series"
|
|
RankingsPath = "/rankings"
|
|
LatestPath = "/latest"
|
|
FeaturedPath = "/featured"
|
|
)
|
|
|
|
// Segment receives a raw model slug. Escape exactly once so slashes, queries and
|
|
// percent signs remain part of that single segment, matching the H5 route helper.
|
|
func Segment(slug string, id int64) string {
|
|
return url.PathEscape(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(DramaPath, 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 CollectionsPath
|
|
}
|
|
return Entity(CollectionPath, slug, id)
|
|
}
|
|
|
|
func Tag(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity(TagsPath, slug, id)
|
|
}
|
|
|
|
func ListTheme(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return DramaListPath
|
|
}
|
|
return Entity(DramaListPath, slug, id)
|
|
}
|
|
|
|
func VideoPlay(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity(SeriesWatchPath, slug, id)
|
|
}
|
|
|
|
func MoreList(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity(CuratedDramasPath, slug, id)
|
|
}
|
|
|
|
func MoreSeriesList(slug string, id int64) string {
|
|
if Segment(slug, id) == "" {
|
|
return ""
|
|
}
|
|
return Entity(CuratedSeriesPath, slug, id)
|
|
}
|
|
|
|
func SeriesTopic(topicID int64) string {
|
|
if topicID <= 0 {
|
|
return SeriesPath
|
|
}
|
|
return SeriesPath + "/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 页面绝对地址,统一保留尾斜杠
|
|
func SitemapAbs(webAddr, path string) string {
|
|
path = strings.TrimSpace(path)
|
|
if path == "" || path == "/" {
|
|
return utils.JoinUrlPathKeepSlash(webAddr, "/")
|
|
}
|
|
return utils.JoinUrlPathKeepSlash(webAddr, "/"+strings.Trim(path, "/")+"/")
|
|
}
|