鉴权
This commit is contained in:
@@ -144,15 +144,23 @@ func GetSlugAbbr(text string) string {
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// MakeAbbrSlug 优先按标题拼音首字母缩写生成 slug;缩写为空或全数字时回退 5 位随机字母,碰撞时追加 3 位随机字母。
|
||||
// AbbrSlugMaxLen slug 最大长度(含碰撞时追加的随机后缀)。
|
||||
const AbbrSlugMaxLen = 20
|
||||
|
||||
// MakeAbbrSlug 优先按标题拼音首字母缩写生成 slug;缩写为空或全数字时回退 5 位随机字母,碰撞时追加 3 位随机字母,整体长度不超过 AbbrSlugMaxLen。
|
||||
func MakeAbbrSlug(source string, exists func(string) bool) string {
|
||||
abbr := GetSlugAbbr(source)
|
||||
if abbr == "" || IsSlugAllDigits(abbr) {
|
||||
abbr = strings.ToLower(GetRandomLetters(5))
|
||||
}
|
||||
const suffixLen = 3
|
||||
baseMax := AbbrSlugMaxLen - suffixLen
|
||||
if len(abbr) > baseMax {
|
||||
abbr = abbr[:baseMax]
|
||||
}
|
||||
final := abbr
|
||||
for exists(final) {
|
||||
final = abbr + strings.ToLower(GetRandomLetters(3))
|
||||
final = abbr + strings.ToLower(GetRandomLetters(suffixLen))
|
||||
}
|
||||
return final
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user