Refactor project slug handling and improve project retrieval logic
All checks were successful
Build and Deploy Gabriel Kaszewski Portfolio / build-and-deploy-local (push) Successful in 1m46s
All checks were successful
Build and Deploy Gabriel Kaszewski Portfolio / build-and-deploy-local (push) Successful in 1m46s
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Skill, Job, Project, FunZoneItem, Writing, Photo } from "@/lib/types";
|
||||
import { slugify } from "@/lib/slug";
|
||||
|
||||
export const skills: Skill[] = [
|
||||
{ name: "Angular" },
|
||||
@@ -628,3 +629,8 @@ export const photos: Photo[] = [
|
||||
height: 2000,
|
||||
},
|
||||
];
|
||||
|
||||
export const projectSlug = (project: Project): string => slugify(project.name);
|
||||
|
||||
export const getProjectBySlug = (slug: string): Project | undefined =>
|
||||
projects.find((project) => projectSlug(project) === slug);
|
||||
|
||||
10
lib/slug.ts
Normal file
10
lib/slug.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export function slugify(value: string): string {
|
||||
return value
|
||||
.normalize("NFD")
|
||||
.replace(/\p{Diacritic}/gu, "")
|
||||
.replace(/ł/g, "l")
|
||||
.replace(/Ł/g, "L")
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9]+/g, "-")
|
||||
.replace(/^-+|-+$/g, "");
|
||||
}
|
||||
Reference in New Issue
Block a user