Started working on the blogs
This commit is contained in:
11
frontend/lib/sluggify.ts
Normal file
11
frontend/lib/sluggify.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export default function sluggify(text: string): string {
|
||||
return text
|
||||
.toLowerCase() // Convert to lowercase
|
||||
.trim() // Remove leading/trailing whitespace
|
||||
.normalize("NFD") // Normalize special characters
|
||||
.replace(/[\u0300-\u036f]/g, "") // Remove diacritics
|
||||
.replace(/[^a-z0-9\s-]/g, "") // Remove special characters except spaces and hyphens
|
||||
.replace(/\s+/g, "-") // Replace spaces with hyphens
|
||||
.replace(/-+/g, "-") // Replace multiple hyphens with single hyphen
|
||||
.slice(0, 100); // Limit length to 100 characters
|
||||
}
|
||||
Reference in New Issue
Block a user