You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
440 B
16 lines
440 B
export const POST_SLUG_RE = /^[a-z0-9][a-z0-9-]{0,98}[a-z0-9]$|^[a-z0-9]$/
|
|
|
|
export function normalizePostSlugCandidate(input: string): string {
|
|
const ascii = input
|
|
.toLowerCase()
|
|
.normalize('NFKD')
|
|
.replace(/[\u0300-\u036f]/g, '')
|
|
.replace(/['"]/g, '')
|
|
.replace(/[^a-z0-9]+/g, '-')
|
|
.replace(/^-+|-+$/g, '')
|
|
.replace(/-{2,}/g, '-')
|
|
|
|
const limited = ascii.slice(0, 100).replace(/-+$/g, '')
|
|
return limited
|
|
}
|
|
|
|
|