parse special characters for cactus id

This commit is contained in:
pluja 2024-03-25 11:33:45 +01:00
parent 71f9a8cfff
commit 88e97900c2
2 changed files with 18 additions and 1 deletions

View File

@ -263,7 +263,7 @@ initComments({
defaultHomeserverUrl: "https://matrix.cactus.chat:8448",
serverName: "cactus.chat",
siteName: "kycnot.me",
commentSectionId: "{{.Service.Name}}",
commentSectionId: "{{toId .Service.Name}}",
guestPostingEnabled: false
})
</script>

View File

@ -7,6 +7,7 @@ import (
"net/http"
"os"
"path"
"regexp"
"strings"
"time"
@ -138,6 +139,22 @@ func (s *Server) RegisterViews() {
"safe": func(s string) template.HTML {
return template.HTML(s)
},
"toId": func(s string) string {
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
if err != nil {
log.Debug().Err(err).Msg("toId error")
return strings.Replace(strings.ToLower(s), " ", "-", -1)
}
processedString := reg.ReplaceAllString(s, "-")
regReplace, err := regexp.Compile("-+")
if err != nil {
log.Debug().Err(err).Msg("toId error")
return strings.Replace(strings.ToLower(s), " ", "-", -1)
}
processedString = regReplace.ReplaceAllString(processedString, "-")
return strings.ToLower(processedString)
},
"randomElem": func(vs []string) string {
if len(vs) == 0 {
return ""