v3: added content slugs, fixed real-time updates in client, added @mentions across the app, added new file selector and drop zone
This commit is contained in:
18
api/lib/slugify.ts
Normal file
18
api/lib/slugify.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export const UUID_RE =
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
||||
|
||||
export function slugify(title: string): string {
|
||||
const slug = title
|
||||
.toLowerCase()
|
||||
.normalize("NFD")
|
||||
.replace(/[\u0300-\u036f]/g, "") // strip diacritics
|
||||
.replace(/[^a-z0-9]+/g, "-") // non-alphanumeric → dash
|
||||
.replace(/^-+|-+$/g, "") // trim leading/trailing dashes
|
||||
.substring(0, 60);
|
||||
return slug || "untitled";
|
||||
}
|
||||
|
||||
/** Stable slug tied to the record's id — unique by construction. */
|
||||
export function makeSlug(title: string, id: string): string {
|
||||
return `${slugify(title)}-${id.substring(0, 8)}`;
|
||||
}
|
||||
Reference in New Issue
Block a user