people: Extract function to convert full name to URL slug.

This commit is contained in:
Aman Agrawal
2025-08-26 11:51:25 +05:30
committed by Tim Abbott
parent 9a0ac354ed
commit f5dc7f41be

View File

@@ -653,6 +653,10 @@ export function pm_perma_link(message: Message): string | undefined {
return url;
}
export function get_slug_from_full_name(full_name: string): string {
return full_name.replaceAll(/[ "%/<>`\p{C}]+/gu, "-");
}
export function pm_with_url(message: Message | MessageWithBooleans): string | undefined {
const user_ids = pm_with_user_ids(message);
@@ -667,7 +671,7 @@ export function pm_with_url(message: Message | MessageWithBooleans): string | un
} else {
const person = maybe_get_user_by_id(user_ids[0]);
if (person?.full_name) {
suffix = person.full_name.replaceAll(/[ "%/<>`\p{C}]+/gu, "-");
suffix = get_slug_from_full_name(person.full_name);
} else {
blueslip.error("Unknown people in message");
suffix = "unk";
@@ -759,8 +763,7 @@ export function emails_to_slug(emails_string: string): string | undefined {
if (emails.length === 1 && emails[0] !== undefined) {
const person = get_by_email(emails[0]);
assert(person !== undefined, "Unknown person in emails_to_slug");
const name = person.full_name;
slug += name.replaceAll(/[ "%/<>`\p{C}]+/gu, "-");
slug += get_slug_from_full_name(person.full_name);
} else {
slug += "group";
}