mirror of
https://github.com/chillpadclub/bedolaga-cabinet.git
synced 2026-07-29 18:13:47 +00:00
fix: transliterate Cyrillic to Latin in news slug generation
This commit is contained in:
@@ -165,10 +165,49 @@ function isSafeUrl(url: string | null | undefined): boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// --- Slug utility ---
|
// --- Slug utility ---
|
||||||
|
const TRANSLIT_MAP: Record<string, string> = {
|
||||||
|
а: 'a',
|
||||||
|
б: 'b',
|
||||||
|
в: 'v',
|
||||||
|
г: 'g',
|
||||||
|
д: 'd',
|
||||||
|
е: 'e',
|
||||||
|
ё: 'yo',
|
||||||
|
ж: 'zh',
|
||||||
|
з: 'z',
|
||||||
|
и: 'i',
|
||||||
|
й: 'y',
|
||||||
|
к: 'k',
|
||||||
|
л: 'l',
|
||||||
|
м: 'm',
|
||||||
|
н: 'n',
|
||||||
|
о: 'o',
|
||||||
|
п: 'p',
|
||||||
|
р: 'r',
|
||||||
|
с: 's',
|
||||||
|
т: 't',
|
||||||
|
у: 'u',
|
||||||
|
ф: 'f',
|
||||||
|
х: 'kh',
|
||||||
|
ц: 'ts',
|
||||||
|
ч: 'ch',
|
||||||
|
ш: 'sh',
|
||||||
|
щ: 'shch',
|
||||||
|
ъ: '',
|
||||||
|
ы: 'y',
|
||||||
|
ь: '',
|
||||||
|
э: 'e',
|
||||||
|
ю: 'yu',
|
||||||
|
я: 'ya',
|
||||||
|
};
|
||||||
|
|
||||||
function generateSlug(title: string): string {
|
function generateSlug(title: string): string {
|
||||||
return title
|
const lower = title.toLowerCase();
|
||||||
.toLowerCase()
|
const transliterated = Array.from(lower)
|
||||||
.replace(/[^\w\s\-а-яёА-ЯЁ]/g, '')
|
.map((ch) => TRANSLIT_MAP[ch] ?? ch)
|
||||||
|
.join('');
|
||||||
|
return transliterated
|
||||||
|
.replace(/[^a-z0-9\s-]/g, '')
|
||||||
.replace(/[\s_]+/g, '-')
|
.replace(/[\s_]+/g, '-')
|
||||||
.replace(/-+/g, '-')
|
.replace(/-+/g, '-')
|
||||||
.replace(/^-+|-+$/g, '')
|
.replace(/^-+|-+$/g, '')
|
||||||
|
|||||||
Reference in New Issue
Block a user