专题 canonical URL 由 /list?themeId=X 改为 /topic/[slug]/
与 sitemap 输出和前端规范地址保持一致,避免 canonical 指向会被 301 的旧路径。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -2,13 +2,13 @@ package playletthemeser
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"videoweb/app/api/proto"
|
"videoweb/app/api/proto"
|
||||||
"videoweb/app/service/configser"
|
"videoweb/app/service/configser"
|
||||||
"videoweb/app/service/playletcache"
|
"videoweb/app/service/playletcache"
|
||||||
"videoweb/pub/common/netutil"
|
"videoweb/pub/common/netutil"
|
||||||
"videoweb/pub/common/srvdef"
|
"videoweb/pub/common/srvdef"
|
||||||
|
"videoweb/pub/common/utils"
|
||||||
"videoweb/pub/pubdef"
|
"videoweb/pub/pubdef"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -54,11 +54,18 @@ func buildThemeSeoInfo(item *playletcache.ThemeItem) *proto.SeoInfo {
|
|||||||
if len(custom.Keyworld) > 0 {
|
if len(custom.Keyworld) > 0 {
|
||||||
seo.Keywords = append([]string{}, custom.Keyworld...)
|
seo.Keywords = append([]string{}, custom.Keyworld...)
|
||||||
}
|
}
|
||||||
pagePath := "/list?themeId=" + strconv.FormatInt(item.Id, 10)
|
seo.CanonicalURL = joinCanonicalURL(seo.CanonicalURL, buildThemeCanonicalPath(item.Slug, item.Id))
|
||||||
seo.CanonicalURL = joinCanonicalURL(seo.CanonicalURL, pagePath)
|
|
||||||
return &seo
|
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 {
|
func normalizeThemeSeoValue(seo pubdef.SeoValue) pubdef.SeoValue {
|
||||||
seo.Title = strings.TrimSpace(seo.Title)
|
seo.Title = strings.TrimSpace(seo.Title)
|
||||||
seo.Description = strings.TrimSpace(seo.Description)
|
seo.Description = strings.TrimSpace(seo.Description)
|
||||||
|
|||||||
Reference in New Issue
Block a user