chore: fix tag regex

This commit is contained in:
Steven
2022-09-05 20:15:34 +08:00
parent 987bb80770
commit d68891d91d
2 changed files with 4 additions and 8 deletions

View File

@@ -12,6 +12,8 @@ import (
"github.com/labstack/echo/v4"
)
var tagRegexp = regexp.MustCompile(`#([^\s#]+?) `)
func (s *Server) registerTagRoutes(g *echo.Group) {
g.GET("/tag", func(c echo.Context) error {
ctx := c.Request().Context()
@@ -47,13 +49,9 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
tagMapSet := make(map[string]bool)
r := regexp.MustCompile(`#([^\s#]+?) `)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to compile regexp").SetInternal(err)
}
for _, memo := range memoList {
for _, rawTag := range r.FindAllString(memo.Content, -1) {
tag := r.ReplaceAllString(rawTag, "$1")
for _, rawTag := range tagRegexp.FindAllString(memo.Content, -1) {
tag := tagRegexp.ReplaceAllString(rawTag, "$1")
tagMapSet[tag] = true
}
}