diff --git a/app/service/playletthemeser/theme.go b/app/service/playletthemeser/theme.go index 0b9b29b..e54bf08 100644 --- a/app/service/playletthemeser/theme.go +++ b/app/service/playletthemeser/theme.go @@ -2,13 +2,13 @@ package playletthemeser import ( "context" - "strconv" "strings" "videoweb/app/api/proto" "videoweb/app/service/configser" "videoweb/app/service/playletcache" "videoweb/pub/common/netutil" "videoweb/pub/common/srvdef" + "videoweb/pub/common/utils" "videoweb/pub/pubdef" ) @@ -54,11 +54,18 @@ func buildThemeSeoInfo(item *playletcache.ThemeItem) *proto.SeoInfo { if len(custom.Keyworld) > 0 { seo.Keywords = append([]string{}, custom.Keyworld...) } - pagePath := "/list?themeId=" + strconv.FormatInt(item.Id, 10) - seo.CanonicalURL = joinCanonicalURL(seo.CanonicalURL, pagePath) + seo.CanonicalURL = joinCanonicalURL(seo.CanonicalURL, buildThemeCanonicalPath(item.Slug, item.Id)) return &seo } +// buildThemeCanonicalPath 专题详情页规范相对路径(对齐 sitemap /topic/[slug]/,前端 /list?themeId=X 会被 301)。 +func buildThemeCanonicalPath(slug string, id int64) string { + if segment := utils.PathSegment(slug, id); segment != "" { + return "/topic/" + segment + "/" + } + return "/topic/" +} + func normalizeThemeSeoValue(seo pubdef.SeoValue) pubdef.SeoValue { seo.Title = strings.TrimSpace(seo.Title) seo.Description = strings.TrimSpace(seo.Description)