防止blog urlTitle 无限循环
This commit is contained in:
@ -99,6 +99,7 @@ func encodeValue(val string) string {
|
|||||||
v.Set("", val)
|
v.Set("", val)
|
||||||
return v.Encode()[1:]
|
return v.Encode()[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加笔记时通过title得到urlTitle
|
// 添加笔记时通过title得到urlTitle
|
||||||
func fixUrlTitle(urlTitle string) string {
|
func fixUrlTitle(urlTitle string) string {
|
||||||
if urlTitle != "" {
|
if urlTitle != "" {
|
||||||
@ -119,6 +120,15 @@ func fixUrlTitle(urlTitle string) string {
|
|||||||
|
|
||||||
func getUniqueUrlTitle(userId string, urlTitle string, types string, padding int) string {
|
func getUniqueUrlTitle(userId string, urlTitle string, types string, padding int) string {
|
||||||
urlTitle2 := urlTitle
|
urlTitle2 := urlTitle
|
||||||
|
|
||||||
|
// 判断urlTitle是不是过长, 过长则截断, 300
|
||||||
|
// 不然生成index有问题
|
||||||
|
// it will not index a single field with more than 1024 bytes.
|
||||||
|
// If you're indexing a field that is 2.5MB, it's not really indexing it, it's being skipped.
|
||||||
|
if len(urlTitle2) > 320 {
|
||||||
|
urlTitle2 = urlTitle2[:300] // 为什么要少些, 因为怕无限循环, 因为把padding截了
|
||||||
|
}
|
||||||
|
|
||||||
if padding > 1 {
|
if padding > 1 {
|
||||||
urlTitle2 = urlTitle + "-" + strconv.Itoa(padding)
|
urlTitle2 = urlTitle + "-" + strconv.Itoa(padding)
|
||||||
}
|
}
|
||||||
@ -139,6 +149,7 @@ func getUniqueUrlTitle(userId string, urlTitle string, types string, padding int
|
|||||||
|
|
||||||
return urlTitle2
|
return urlTitle2
|
||||||
}
|
}
|
||||||
|
|
||||||
// types == note,notebook,single
|
// types == note,notebook,single
|
||||||
func GetUrTitle(userId string, title string, types string) string {
|
func GetUrTitle(userId string, title string, types string) string {
|
||||||
urlTitle := strings.Trim(title, " ")
|
urlTitle := strings.Trim(title, " ")
|
||||||
|
Reference in New Issue
Block a user