mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
* wip * wip * wip * wwip * wip * wip * fix(util): rmeove checking to existing in slug * wip * chore: handle create page * chore: handle page title untitled
15 lines
389 B
TypeScript
15 lines
389 B
TypeScript
import slugify from "slugify"
|
|
import crypto from "crypto"
|
|
|
|
export function generateUniqueSlug(title: string, maxLength: number = 60): string {
|
|
const baseSlug = slugify(title, {
|
|
lower: true,
|
|
strict: true
|
|
})
|
|
const randomSuffix = crypto.randomBytes(4).toString("hex")
|
|
|
|
const truncatedSlug = baseSlug.slice(0, Math.min(maxLength, 75) - 9)
|
|
|
|
return `${truncatedSlug}-${randomSuffix}`
|
|
}
|