专题 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 (
|
||||
"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)
|
||||
|
||||
Reference in New Issue
Block a user