| 1 | import { customAlphabet } from 'nanoid'; |
| 2 | import slugify from 'slugify'; |
| 3 | |
| 4 | const slugAlphabet = customAlphabet( |
| 5 | '_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', |
| 6 | 10, |
| 7 | ); |
| 8 | |
| 9 | export function titleToSlug(title: string) { |
| 10 | const slugified = slugify(title, { lower: true }); |
| 11 | const slugifiedWithSuffix = `${slugified}-${slugAlphabet()}`; |
| 12 | return { |
| 13 | slugified, |
| 14 | slugifiedWithSuffix, |
| 15 | }; |
| 16 | } |