nip54: update d-tag normalization rules.

This commit is contained in:
fiatjaf
2026-03-18 19:12:40 -03:00
parent 2cec1c9434
commit 1520264394
2 changed files with 13 additions and 9 deletions
+12 -8
View File
@@ -11,20 +11,24 @@ import (
)
func NormalizeIdentifier(name string) string {
name = strings.TrimSpace(strings.ToLower(name))
res, _, _ := transform.Bytes(norm.NFKC, []byte(name))
runes := []rune(string(res))
runes := []rune(strings.ToLower(string(res)))
b := make([]rune, len(runes))
for i, letter := range runes {
words := make([]string, 0, 3)
word := make([]rune, 0, 12)
for _, letter := range runes {
if unicode.IsLetter(letter) || unicode.IsNumber(letter) {
b[i] = letter
} else {
b[i] = '-'
word = append(word, letter)
} else if len(word) > 0 {
words = append(words, string(word))
word = make([]rune, 0, 12)
}
}
if len(word) > 0 {
words = append(words, string(word))
}
return string(b)
return strings.Join(words, "-")
}
func ArticleAsHTML(content string) string {
+1 -1
View File
@@ -13,7 +13,7 @@ func TestNormalization(t *testing.T) {
}{
{" hello ", "hello"},
{"Goodbye", "goodbye"},
{"the long and winding road / that leads to your door", "the-long-and-winding-road---that-leads-to-your-door"},
{"the long and winding road / that leads to your door", "the-long-and-winding-road-that-leads-to-your-door"},
{"it's 平仮名", "it-s-平仮名"},
} {
if norm := NormalizeIdentifier(vector.before); norm != vector.after {