From f8fc2c6ef7440d593630a97e0ad0cecd9f96120b Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Fri, 20 May 2022 12:30:01 -0400 Subject: [PATCH] handle unicode hashtags better --- views/onts.html | 5 +++-- web.go | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/views/onts.html b/views/onts.html index 7873633..cffc8bb 100644 --- a/views/onts.html +++ b/views/onts.html @@ -2,11 +2,12 @@

ontologies of interest +{{ $firstrune := .FirstRune }} {{ $letter := 0 }}

    {{ range .Onts }} -{{ if not (eq $letter (index .Name 0)) }} -{{ $letter = (index .Name 0) }} +{{ if not (eq $letter (call $firstrune .Name)) }} +{{ $letter = (call $firstrune .Name) }}
  • {{ end }} #{{ .Name }} ({{ .Count }}) diff --git a/web.go b/web.go index 21eb95b..a568a50 100644 --- a/web.go +++ b/web.go @@ -32,6 +32,7 @@ import ( "strings" "syscall" "time" + "unicode/utf8" "github.com/gorilla/mux" "humungus.tedunangst.com/r/webs/cache" @@ -855,7 +856,7 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) { elog.Printf("error scanning ont: %s", err) continue } - if len(o.Name) > 24 { + if utf8.RuneCountInString(o.Name) > 24 { continue } o.Name = o.Name[1:] @@ -869,6 +870,7 @@ func thelistingoftheontologies(w http.ResponseWriter, r *http.Request) { } templinfo := getInfo(r) templinfo["Onts"] = onts + templinfo["FirstRune"] = func(s string) rune { r, _ := utf8.DecodeRuneInString(s); return r } err = readviews.Execute(w, "onts.html", templinfo) if err != nil { elog.Print(err)