fix: slugify transliterates now much better

This commit is contained in:
2026-03-01 07:12:38 +01:00
parent 583c37473a
commit 289535021a
7 changed files with 149 additions and 10 deletions

View File

@@ -13,6 +13,7 @@ import { stemText, stemQuery, SupportedLanguage } from './stemmer';
import { readPostFile as readPostFileShared, type PostFileData } from './postFileUtils';
import { CliNotifier, NoopNotifier } from './CliNotifier';
import type { MediaEngine } from './MediaEngine';
import { slugify } from './slugify';
export interface PostData {
id: string;
@@ -216,10 +217,7 @@ export class PostEngine extends EventEmitter {
}
private generateSlug(title: string): string {
return title
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-|-$/g, '');
return slugify(title);
}
/**

View File

@@ -6,6 +6,7 @@ import { eq } from 'drizzle-orm';
import { app } from 'electron';
import { getDatabase } from '../database';
import { projects, posts, media, Project, NewProject } from '../database/schema';
import { slugify } from './slugify';
export interface ProjectData {
id: string;
@@ -43,10 +44,7 @@ export class ProjectEngine extends EventEmitter {
}
private generateSlug(name: string): string {
return name
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-|-$/g, '');
return slugify(name);
}
/**

View File

@@ -0,0 +1,18 @@
import { transliterate } from 'transliteration';
/**
* Generate a URL-safe slug from a string.
*
* - Transliterates umlauts and accented characters to ASCII equivalents
* using the `transliteration` package for broad Unicode coverage
* - Removes non-alphanumeric characters (except hyphens used as separators)
* - Separates words with normal hyphens (U+002D)
* - Collapses consecutive separators into a single hyphen
* - Strips leading/trailing hyphens
*/
export function slugify(input: string): string {
return transliterate(input)
.toLowerCase()
.replace(/[^a-z0-9]+/g, '-')
.replace(/^-+|-+$/g, '');
}