feat(ods): normalize all unicode characters to their ascii equivalents
This commit is contained in:
parent
e389a0e925
commit
a6fd4a153d
2 changed files with 12 additions and 5 deletions
2
go.mod
2
go.mod
|
@ -1,3 +1,5 @@
|
|||
module git.adyxax.org/adyxax/ods/v2
|
||||
|
||||
go 1.22.1
|
||||
|
||||
require golang.org/x/text v0.14.0 // indirect
|
||||
|
|
7
main.go
7
main.go
|
@ -2,10 +2,14 @@ package main
|
|||
|
||||
import (
|
||||
"embed"
|
||||
"golang.org/x/text/runes"
|
||||
"golang.org/x/text/transform"
|
||||
"golang.org/x/text/unicode/norm"
|
||||
"html/template"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// Variables to customise the search behaviour
|
||||
|
@ -44,6 +48,7 @@ func getIndex() http.Handler {
|
|||
}
|
||||
|
||||
func postIndex() http.Handler {
|
||||
normalizer := transform.Chain(norm.NFD, runes.Remove(runes.In(unicode.Mn)), norm.NFC)
|
||||
words := strings.Split(ods, "\n")
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
data := IndexData{
|
||||
|
@ -51,7 +56,7 @@ func postIndex() http.Handler {
|
|||
Query: r.FormValue("query"),
|
||||
Invalid: true,
|
||||
}
|
||||
query := strings.TrimSpace(strings.ToUpper(data.Query))
|
||||
query, _, _ := transform.String(normalizer, strings.TrimSpace(strings.ToUpper(data.Query)))
|
||||
for _, w := range words {
|
||||
if w == query {
|
||||
data.Invalid = false
|
||||
|
|
Loading…
Add table
Reference in a new issue