Refactor: Implement app-wide slug generation

This commit is contained in:
gpt-engineer-app[bot]
2025-10-01 17:02:03 +00:00
parent 8cd6a35fcf
commit 91afb4f769
9 changed files with 185 additions and 207 deletions

View File

@@ -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
*/