24 lines
529 B
TypeScript
24 lines
529 B
TypeScript
// app/(builder)/parts/_components/buildDetailHref.ts
|
|
|
|
const toSlug = (str: string) =>
|
|
str
|
|
.toLowerCase()
|
|
.replace(/[^a-z0-9]+/g, "-")
|
|
.replace(/(^-|-$)/g, "");
|
|
|
|
export type BuildDetailInput = {
|
|
id: string;
|
|
name: string;
|
|
brand?: string;
|
|
};
|
|
|
|
export function buildDetailHref(
|
|
platform: string,
|
|
partRole: string,
|
|
p: BuildDetailInput
|
|
) {
|
|
const slug = toSlug(`${p.brand ?? ""} ${p.name ?? ""}`);
|
|
return `/parts/p/${encodeURIComponent(platform)}/${encodeURIComponent(
|
|
partRole
|
|
)}/${p.id}-${slug}`;
|
|
} |