init: web_hgcg_server 初始化提交

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 16:44:55 +08:00
co-authored by Claude Opus 4.7
commit 189556e702
627 changed files with 126228 additions and 0 deletions
+115
View File
@@ -0,0 +1,115 @@
// Package h5path 统一拼装 jha-1045-hgdjnet-web 的页面路径。
// Abs 保持原有无尾斜杠规范,SitemapAbs 专用于 sitemap 页面 URL
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)
}
// Detail 短剧详情页,对应 H5 /detail/{slug|id}/。
func Detail(slug string, id int64) string {
if Segment(slug, id) == "" {
return ""
}
return Entity("/detail", slug, id)
}
// Topic 专题详情页,对应 H5 /topics/{slug|id}/。
func Topic(slug string, id int64) string {
if Segment(slug, id) == "" {
return ""
}
return Entity("/topics", slug, id)
}
// ContentTag 标签列表页,对应 H5 /tag/{slug|id}/。
func ContentTag(slug string, id int64) string {
if Segment(slug, id) == "" {
return ""
}
return Entity("/tag", slug, id)
}
// HomeMore 首页模块更多页,对应 H5 /config/{slug|id}/。
func HomeMore(slug string, id int64) string {
if Segment(slug, id) == "" {
return ""
}
return Entity("/config", 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 MoreList(slug string, id int64) string {
if Segment(slug, id) == "" {
return ""
}
return Entity("/more-list", slug, id)
}
// 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, "/")+"/")
}
+31
View File
@@ -0,0 +1,31 @@
package h5path
import "testing"
func TestSitemapAbsKeepsTrailingSlash(t *testing.T) {
tests := []struct {
name string
path string
want string
}{
{name: "home", path: "/", want: "https://huangguo.net/"},
{name: "list", path: "/list", want: "https://huangguo.net/list/"},
{name: "playlet", path: "/play/demo", want: "https://huangguo.net/play/demo/"},
{name: "already_slash", path: "/play/demo/", want: "https://huangguo.net/play/demo/"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := SitemapAbs("https://huangguo.net", tt.path)
if got != tt.want {
t.Fatalf("SitemapAbs() = %q, want %q", got, tt.want)
}
})
}
}
func TestAbsKeepsExistingBehavior(t *testing.T) {
got := Abs("https://huangguo.net", "/list")
if got != "https://huangguo.net/list" {
t.Fatalf("Abs() = %q, want %q", got, "https://huangguo.net/list")
}
}