Further wiki slug normalization
This commit is contained in:
@@ -175,6 +175,8 @@ func TestDeploySlugifyWikiTitleMatchesGeneratedSlugPolicy(t *testing.T) {
|
|||||||
`Hardiness vs. Enchantments`: "hardiness-vs-enchantments",
|
`Hardiness vs. Enchantments`: "hardiness-vs-enchantments",
|
||||||
`Clairaudience/Clairvoyance`: "clairaudience-clairvoyance",
|
`Clairaudience/Clairvoyance`: "clairaudience-clairvoyance",
|
||||||
`Élite & Noble Houses`: "elite-noble-houses",
|
`Élite & Noble Houses`: "elite-noble-houses",
|
||||||
|
`Alpha!@#$%^&*()[]-=_+/?.,<>` + "`" + `~|\Omega`: "alpha-omega",
|
||||||
|
`Æther Œuvre Øresund Straße Þorn Łódź Đelta`: "aether-oeuvre-oresund-strasse-thorn-lodz-delta",
|
||||||
}
|
}
|
||||||
for input, want := range tests {
|
for input, want := range tests {
|
||||||
if got := slugifyWikiTitle(input); got != want {
|
if got := slugifyWikiTitle(input); got != want {
|
||||||
|
|||||||
@@ -1250,6 +1250,8 @@ func TestWikiSlugifyTitleNormalizesPunctuationAndSeparators(t *testing.T) {
|
|||||||
`Élite & Noble Houses`: "elite-noble-houses",
|
`Élite & Noble Houses`: "elite-noble-houses",
|
||||||
`Rock 'n' Roll`: "rock-n-roll",
|
`Rock 'n' Roll`: "rock-n-roll",
|
||||||
`Melf's Acid Arrow`: "melfs-acid-arrow",
|
`Melf's Acid Arrow`: "melfs-acid-arrow",
|
||||||
|
`Alpha!@#$%^&*()[]-=_+/?.,<>` + "`" + `~|\Omega`: "alpha-omega",
|
||||||
|
`Æther Œuvre Øresund Straße Þorn Łódź Đelta`: "aether-oeuvre-oresund-strasse-thorn-lodz-delta",
|
||||||
}
|
}
|
||||||
for input, want := range tests {
|
for input, want := range tests {
|
||||||
if got := wikiSlugifyTitle(input); got != want {
|
if got := wikiSlugifyTitle(input); got != want {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ func slugifyWikiText(value string, fallback string) string {
|
|||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
lastDash := false
|
lastDash := false
|
||||||
for _, r := range norm.NFKD.String(strings.ToLower(value)) {
|
for _, r := range norm.NFKD.String(strings.ToLower(value)) {
|
||||||
|
transliterated := transliterateWikiSlugRune(r)
|
||||||
switch {
|
switch {
|
||||||
case r >= 'a' && r <= 'z':
|
case r >= 'a' && r <= 'z':
|
||||||
b.WriteRune(r)
|
b.WriteRune(r)
|
||||||
@@ -24,6 +25,9 @@ func slugifyWikiText(value string, fallback string) string {
|
|||||||
continue
|
continue
|
||||||
case isWikiSlugJoinerPunctuation(r):
|
case isWikiSlugJoinerPunctuation(r):
|
||||||
continue
|
continue
|
||||||
|
case transliterated != "":
|
||||||
|
b.WriteString(transliterated)
|
||||||
|
lastDash = false
|
||||||
default:
|
default:
|
||||||
if b.Len() > 0 && !lastDash {
|
if b.Len() > 0 && !lastDash {
|
||||||
b.WriteByte('-')
|
b.WriteByte('-')
|
||||||
@@ -46,3 +50,32 @@ func isWikiSlugJoinerPunctuation(r rune) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func transliterateWikiSlugRune(r rune) string {
|
||||||
|
switch r {
|
||||||
|
case 'æ':
|
||||||
|
return "ae"
|
||||||
|
case 'œ':
|
||||||
|
return "oe"
|
||||||
|
case 'ø':
|
||||||
|
return "o"
|
||||||
|
case 'ß':
|
||||||
|
return "ss"
|
||||||
|
case 'þ':
|
||||||
|
return "th"
|
||||||
|
case 'ð', 'đ':
|
||||||
|
return "d"
|
||||||
|
case 'ł':
|
||||||
|
return "l"
|
||||||
|
case 'ħ':
|
||||||
|
return "h"
|
||||||
|
case 'ı':
|
||||||
|
return "i"
|
||||||
|
case 'ŋ':
|
||||||
|
return "n"
|
||||||
|
case 'ŧ':
|
||||||
|
return "t"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user