Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
fix(slug): transliterate non-ASCII letters instead of deleting them (#763)
Shahzain Shafique05f2b164638e
diff --git a/web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx b/web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsxindex 2b27ab1b0..e0704f67b 100644--- a/web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx+++ b/web/src/app/[locale]/(onboarding)/dashboard/onboarding/page.tsx@@ -9,6 +9,7 @@ import { getPromptCapacity, savePromptSet } from '@/lib/actions/prompt';import { triggerTrackingCheck } from '@/lib/actions/tracking';import { addCompetitor, getCompetitors } from '@/lib/actions/competitor';import { getFaviconUrl } from '@/lib/favicon';+import { slugify } from '@/lib/slug';import { useBrandStore } from '@/stores/use-brand-store';import { REGIONS, US_STATES, LANGUAGES } from '@/config/prompt-options';import { ALL_MODELS, ALL_SCRAPERS } from '@/config/prompt-options';@@ -511,14 +512,7 @@ export default function OnboardingPage() {let orgId = profile?.organization_id;if (!orgId) {- const slug =- brandName- .toLowerCase()- .trim()- .replace(/\s+/g, '-')- .replace(/[^a-z0-9-]/g, '')- .replace(/-+/g, '-')- .replace(/^-|-$/g, '') || `org-${Date.now()}`;+ const slug = slugify(brandName) || `org-${Date.now()}`;const { data: existing } = await supabase.from('organizations')diff --git a/web/src/lib/actions/brand.ts b/web/src/lib/actions/brand.tsindex eecf572ba..3f3e56102 100644--- a/web/src/lib/actions/brand.ts+++ b/web/src/lib/actions/brand.ts@@ -3,18 +3,9 @@import { createClient } from '@/lib/supabase/server';import { revalidatePath } from 'next/cache';import { enforceLimit } from '@/lib/guards/plan-guard';+import { slugify } from '@/lib/slug';import type { Brand, BrandDomain } from '@/types';-function slugify(text: string): string {- return text- .toLowerCase()- .trim()- .replace(/\s+/g, '-')- .replace(/[^a-z0-9-]/g, '')- .replace(/-+/g, '-')- .replace(/^-|-$/g, '');-}-function mapDomainRow(d: Record<string, unknown>): BrandDomain {return {id: d.id as string,diff --git a/web/src/lib/actions/organization.ts b/web/src/lib/actions/organization.tsindex edeaa1223..144005bcc 100644--- a/web/src/lib/actions/organization.ts+++ b/web/src/lib/actions/organization.ts@@ -2,16 +2,7 @@import { createClient } from '@/lib/supabase/server';import { revalidatePath } from 'next/cache';--function slugify(text: string): string {- return text- .toLowerCase()- .trim()- .replace(/\s+/g, '-')- .replace(/[^a-z0-9-]/g, '')- .replace(/-+/g, '-')- .replace(/^-|-$/g, '');-}+import { slugify } from '@/lib/slug';export async function createOrganization(name: string) {const supabase = await createClient();diff --git a/web/src/lib/slug.test.ts b/web/src/lib/slug.test.tsnew file mode 100644index 000000000..83ca1be22--- /dev/null+++ b/web/src/lib/slug.test.ts@@ -0,0 +1,45 @@+import { expect, test } from 'vitest';+import { slugify } from './slug.js';++test('plain ASCII names lowercase and hyphenate', () => {+ expect(slugify('Hello World')).toBe('hello-world');+ expect(slugify('Acme Corp')).toBe('acme-corp');+});++test('accented Latin letters are transliterated, not deleted', () => {+ expect(slugify('Öz Güven')).toBe('oz-guven');+ expect(slugify('Ürün')).toBe('urun');+ expect(slugify('Müller')).toBe('muller');+ expect(slugify('Çiğdem')).toBe('cigdem');+ expect(slugify('café')).toBe('cafe');+});++test('Turkish letters that do not decompose are handled', () => {+ expect(slugify('Şeker')).toBe('seker');+ expect(slugify('Ağaç')).toBe('agac');+});++test('Turkish dotless/dotted i is pinned to i regardless of lowercasing', () => {+ expect(slugify('Işık')).toBe('isik');+ expect(slugify('İstanbul')).toBe('istanbul');+});++test('names that used to collapse to the same slug now stay distinct', () => {+ expect(slugify('Ağaç')).not.toBe(slugify('Aa'));+});++test('German ß, Nordic ø, and Polish ł are transliterated', () => {+ expect(slugify('Straße')).toBe('strasse');+ expect(slugify('Nørgaard')).toBe('norgaard');+ expect(slugify('Łódź')).toBe('lodz');+});++test('whitespace collapses and edge hyphens are trimmed', () => {+ expect(slugify(' Öz Güven ')).toBe('oz-guven');+ expect(slugify('--Ürün--')).toBe('urun');+});++test('returns an empty string when nothing survives', () => {+ expect(slugify('!!!')).toBe('');+ expect(slugify(' ')).toBe('');+});diff --git a/web/src/lib/slug.ts b/web/src/lib/slug.tsnew file mode 100644index 000000000..fdb74096f--- /dev/null+++ b/web/src/lib/slug.ts@@ -0,0 +1,52 @@+// Letters that Unicode NFD does not decompose on its own (Turkish dotless/dotted+// i, German ß, Nordic ø, Polish ł, …), plus the Turkish I/ı lowercasing case.+// This map is the single source of truth for the special-case set: the pattern+// below is derived from its keys, and every other non-ASCII letter falls through+// to the NFD pass in `slugify` (é → e, ü → u, ç → c).+const TRANSLITERATIONS: Record<string, string> = {+ ı: 'i',+ İ: 'i',+ I: 'i',+ ş: 's',+ Ş: 's',+ ğ: 'g',+ Ğ: 'g',+ ß: 'ss',+ ø: 'o',+ Ø: 'o',+ ł: 'l',+ Ł: 'l',+ đ: 'd',+ Đ: 'd',+ ð: 'd',+ Ð: 'd',+ þ: 'th',+ Þ: 'th',+ æ: 'ae',+ Æ: 'ae',+ œ: 'oe',+ Œ: 'oe',+};++const TRANSLITERATION_PATTERN = new RegExp(`[${Object.keys(TRANSLITERATIONS).join('')}]`, 'g');++/**+ * Turn a display name into a URL/filename-safe slug.+ *+ * Non-ASCII letters are transliterated rather than deleted, so `Ürün` becomes+ * `urun` (not `rn`) and every CSV/PDF export named after the slug keeps the+ * brand's name. Returns an empty string when nothing survives; callers supply+ * their own fallback for that case.+ */+export function slugify(text: string): string {+ return text+ .replace(TRANSLITERATION_PATTERN, (ch) => TRANSLITERATIONS[ch] ?? ch)+ .normalize('NFD')+ .replace(/[\u0300-\u036f]/g, '')+ .toLowerCase()+ .trim()+ .replace(/\s+/g, '-')+ .replace(/[^a-z0-9-]/g, '')+ .replace(/-+/g, '-')+ .replace(/^-|-$/g, '');+}