Skip to content

Commit e9cf3fa

Browse files
committed
feat: make slugify func more robust
1 parent 0528999 commit e9cf3fa

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Post.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,13 @@ export const ReactionBar = ({
345345
};
346346

347347
function slugify(s: string): string {
348-
return lowerCase(s).replace(/[^A-Za-z0-9-]+/g, '-');
348+
return lowerCase(s)
349+
.replace(/\s+/g, '-') // Replace spaces with -
350+
.replace(/&/g, '-and-') // Replace & with 'and'
351+
.replace(/[^\w\-]+/g, '') // Remove all non-word characters
352+
.replace(/\-\-+/g, '-') // Replace multiple - with single -
353+
.trimStart() // Trim from start of text
354+
.trimEnd(); // Trim from end of text
349355
}
350356

351357
export function postUrl({

0 commit comments

Comments
 (0)