fix: tag regexp (#409)

* chore: enable `no-unused-vars`

* fix: tag regexp
This commit is contained in:
boojack 2022-11-04 08:28:29 +08:00 committed by GitHub
parent c27e38b11c
commit 8e2844e0c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -12,7 +12,7 @@ import (
"github.com/labstack/echo/v4"
)
var tagRegexp = regexp.MustCompile(`[^\s]?#([^\s#]+?) `)
var tagRegexpList = []*regexp.Regexp{regexp.MustCompile(`^#([^\s#]+?) `), regexp.MustCompile(`\s#([^\s#]+?) `)}
func (s *Server) registerTagRoutes(g *echo.Group) {
g.GET("/tag", func(c echo.Context) error {
@ -50,9 +50,11 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
tagMapSet := make(map[string]bool)
for _, memo := range memoList {
for _, rawTag := range tagRegexp.FindAllString(memo.Content, -1) {
tag := tagRegexp.ReplaceAllString(rawTag, "$1")
tagMapSet[tag] = true
for _, tagRegexp := range tagRegexpList {
for _, rawTag := range tagRegexp.FindAllString(memo.Content, -1) {
tag := tagRegexp.ReplaceAllString(rawTag, "$1")
tagMapSet[tag] = true
}
}
}