Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
const EVENT_UUID_PATTERN = /^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/i
|
|
const EVENT_SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
|
|
|
|
// Keep application-route words and UUID-shaped values out of public slugs.
|
|
// UUIDs are still accepted by `/e/[slug]` as private/legacy identifiers, but
|
|
// are never considered canonical SEO URLs.
|
|
export const RESERVED_EVENT_SLUGS = new Set(['new'])
|
|
|
|
export const isEventUuid = (value: string) => EVENT_UUID_PATTERN.test(value)
|
|
|
|
export const isPublicEventSlug = (value: string) =>
|
|
EVENT_SLUG_PATTERN.test(value) && !isEventUuid(value) && !RESERVED_EVENT_SLUGS.has(value)
|
|
|
|
const getSingleSegment = (pathname: string, prefix: string) => {
|
|
const match = new RegExp(`^/${prefix}/([^/]+)/?$`).exec(pathname)
|
|
|
|
if (!match?.[1]) return null
|
|
|
|
try {
|
|
return decodeURIComponent(match[1])
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
export const isCanonicalEventLandingRoute = (pathname: string) => {
|
|
const segment = getSingleSegment(pathname, 'e')
|
|
|
|
return segment ? isPublicEventSlug(segment) : false
|
|
}
|
|
|
|
export const isLegacyEventDetailRoute = (pathname: string) => {
|
|
const segment = getSingleSegment(pathname, 'events')
|
|
|
|
return segment ? isEventUuid(segment) : false
|
|
}
|
|
|
|
export const isLegacyEventLandingRoute = (pathname: string) => {
|
|
const segment = getSingleSegment(pathname, 'events')
|
|
|
|
return segment ? isPublicEventSlug(segment) : false
|
|
}
|