专题和短剧 slug 改为 8 位随机小写字母

后台新建/修改(未填 slug)和媒资入库时生成随机 slug,不再按标题拼音生成;标签、分类不变。

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-23 22:10:53 +08:00
co-authored by Claude Opus 5.5
parent 5a6cd2a51b
commit ad016ee1ac
3 changed files with 18 additions and 26 deletions
+4 -24
View File
@@ -48,8 +48,7 @@ func ensureThemeSlug(ctx context.Context, ac *playletthememod.PlayletTheme, excl
}
return nil
}
source := utils.SlugSourceFromKeywordsOrTitle(ac.SeoInfo.Keyworld, ac.Name)
ac.Slug = utils.MakeUniqueSlug(source, func(slug string) bool {
ac.Slug = utils.MakeRandomSlug(func(slug string) bool {
filter := bson.M{playletthememod.FN.PlayletTheme.Slug: slug}
if excludeId > 0 {
filter[playletthememod.FN.PlayletTheme.Id] = bson.M{"$ne": excludeId}
@@ -81,16 +80,7 @@ func prepareThemeSlugOnUpdate(ctx context.Context, id int64, info *playletthemem
}
return nil
}
name := info.Name
if req.Name != nil {
name = strings.TrimSpace(*req.Name)
}
keywords := info.SeoInfo.Keyworld
if req.SeoInfo != nil {
keywords = normalizeSeoValue(*req.SeoInfo).Keyworld
}
source := utils.SlugSourceFromKeywordsOrTitle(keywords, name)
newSlug := utils.MakeUniqueSlug(source, func(s string) bool {
newSlug := utils.MakeRandomSlug(func(s string) bool {
exist, _ := playletthememod.FindOnePlayletTheme(ctx, bson.M{
playletthememod.FN.PlayletTheme.Slug: s,
playletthememod.FN.PlayletTheme.Id: bson.M{"$ne": id},
@@ -186,8 +176,7 @@ func ensurePlayletSlug(ctx context.Context, ac *playletmod.Playlet, excludeId in
}
return nil
}
source := utils.SlugSourceFromKeywordsOrTitle(ac.SeoInfo.Keyworld, ac.Title)
ac.Slug = utils.MakeUniqueSlug(source, func(slug string) bool {
ac.Slug = utils.MakeRandomSlug(func(slug string) bool {
filter := bson.M{playletmod.FN.Playlet.Slug: slug}
if excludeId > 0 {
filter[playletmod.FN.Playlet.Id] = bson.M{"$ne": excludeId}
@@ -219,16 +208,7 @@ func preparePlayletSlugOnUpdate(ctx context.Context, id int64, info *playletmod.
}
return nil
}
title := info.Title
if req.Title != nil {
title = strings.TrimSpace(*req.Title)
}
keywords := info.SeoInfo.Keyworld
if req.SeoInfo != nil {
keywords = normalizeSeoValue(*req.SeoInfo).Keyworld
}
source := utils.SlugSourceFromKeywordsOrTitle(keywords, title)
newSlug := utils.MakeUniqueSlug(source, func(s string) bool {
newSlug := utils.MakeRandomSlug(func(s string) bool {
exist, _ := playletmod.FindOnePlaylet(ctx, bson.M{
playletmod.FN.Playlet.Slug: s,
playletmod.FN.Playlet.Id: bson.M{"$ne": id},