fix: slugify transliterates now much better
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
18
src/main/engine/slugify.ts
Normal file
18
src/main/engine/slugify.ts
Normal 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, '');
|
||||
}
|
||||
Reference in New Issue
Block a user