forked from UKSOURCE/hailearning.edu.vn
feat: Refactor blog components and add pagination
This commit is contained in:
20
utils/slugify.ts
Normal file
20
utils/slugify.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* Simple slugify helper (Vietnamese-friendly) to match CMS behavior:
|
||||
* - lowercased
|
||||
* - diacritics removed (NFD)
|
||||
* - "đ" -> "d"
|
||||
* - strict: keep [a-z0-9 -] only, then collapse spaces/hyphens
|
||||
*/
|
||||
export function toSlug(input: string): string {
|
||||
return (input || "")
|
||||
.trim()
|
||||
.toLowerCase()
|
||||
.normalize("NFD")
|
||||
.replace(/[\u0300-\u036f]/g, "")
|
||||
.replace(/đ/g, "d")
|
||||
.replace(/[^a-z0-9\s-]/g, "")
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/-+/g, "-")
|
||||
.replace(/^-|-$/g, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user