mirror of
https://github.com/wgh136/nysoure.git
synced 2025-09-27 12:17:24 +00:00
Unescape and trim whitespace from tag name in URL handling
This commit is contained in:
@@ -2,6 +2,7 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
url2 "net/url"
|
||||||
"nysoure/server/config"
|
"nysoure/server/config"
|
||||||
"nysoure/server/service"
|
"nysoure/server/service"
|
||||||
"nysoure/server/utils"
|
"nysoure/server/utils"
|
||||||
@@ -94,12 +95,16 @@ func serveIndexHtml(c fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
} else if strings.HasPrefix(path, "/tag/") {
|
} else if strings.HasPrefix(path, "/tag/") {
|
||||||
tagName := strings.TrimPrefix(path, "/tag/")
|
tagName := strings.TrimPrefix(path, "/tag/")
|
||||||
|
tagName, err := url2.PathUnescape(tagName)
|
||||||
|
tagName = strings.TrimSpace(tagName)
|
||||||
|
if err == nil {
|
||||||
t, err := service.GetTagByName(tagName)
|
t, err := service.GetTagByName(tagName)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
title = "Tag: " + t.Name
|
title = "Tag: " + t.Name
|
||||||
description = utils.ArticleToDescription(t.Description, 256)
|
description = utils.ArticleToDescription(t.Description, 256)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
content = strings.ReplaceAll(content, "{{SiteName}}", siteName)
|
content = strings.ReplaceAll(content, "{{SiteName}}", siteName)
|
||||||
content = strings.ReplaceAll(content, "{{Description}}", description)
|
content = strings.ReplaceAll(content, "{{Description}}", description)
|
||||||
|
Reference in New Issue
Block a user