Improve handling of accented letters with slugs

This commit is contained in:
Jared Schoeny 2025-10-27 20:07:48 -10:00
parent 9681bd97a7
commit bbd2f56797
2 changed files with 10 additions and 0 deletions

View File

@ -8,6 +8,11 @@ type HackInsert = TablesInsert<"hacks">;
function slugify(text: string) {
return text
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "") // strip combining diacritics
.replace(/ß/g, "ss")
.replace(/æ/g, "ae")
.replace(/œ/g, "oe")
.toLowerCase()
.trim()
.replace(/[^a-z0-9]+/g, "-")

View File

@ -242,6 +242,11 @@ export default function HackSubmitForm({ dummy = false }: HackSubmitFormProps) {
const slugify = (text: string) =>
text
.normalize("NFD")
.replace(/[\u0300-\u036f]/g, "") // strip combining diacritics
.replace(/ß/g, "ss")
.replace(/æ/g, "ae")
.replace(/œ/g, "oe")
.toLowerCase()
.trim()
.replace(/[^a-z0-9]+/g, "-")