mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 18:31:11 -05:00
Refactor: Implement app-wide slug generation
This commit is contained in:
@@ -2,16 +2,28 @@ import { supabase } from '@/integrations/supabase/client';
|
||||
|
||||
/**
|
||||
* Generate a URL-safe slug from a name
|
||||
* This is the canonical slug generation function used throughout the app
|
||||
*/
|
||||
export function generateSlugFromName(name: string): string {
|
||||
if (!name) return '';
|
||||
|
||||
return name
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s-]/g, '')
|
||||
.replace(/\s+/g, '-')
|
||||
.replace(/-+/g, '-')
|
||||
.replace(/[^a-z0-9\s-]/g, '') // Remove non-alphanumeric except spaces and hyphens
|
||||
.replace(/\s+/g, '-') // Replace spaces with hyphens
|
||||
.replace(/-+/g, '-') // Replace multiple hyphens with single hyphen
|
||||
.replace(/^-+|-+$/g, '') // Remove leading/trailing hyphens
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a user has permission to edit slugs
|
||||
* Only moderators should be able to manually edit slugs
|
||||
*/
|
||||
export function canEditSlug(isModerator: boolean): boolean {
|
||||
return isModerator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure slug is unique by checking database and appending number if needed
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user