Better slugs, improvements to projects, some fixes
All checks were successful
Build and Deploy to Web Server / deploy (push) Successful in 14m57s
All checks were successful
Build and Deploy to Web Server / deploy (push) Successful in 14m57s
This commit is contained in:
@@ -14,6 +14,23 @@ const allProjectHeros = import.meta.glob<{ default: ImageMetadata }>(
|
||||
{ eager: true }
|
||||
);
|
||||
|
||||
const allImages = import.meta.glob<{ default: ImageMetadata }>(
|
||||
"/**/*.{jpeg,jpg,png,gif}",
|
||||
{
|
||||
eager: true
|
||||
}
|
||||
);
|
||||
|
||||
export function getImageByPath(path: string): ImageMetadata | null {
|
||||
for (const [imagePath, mod] of Object.entries(allImages)) {
|
||||
if (imagePath.includes(path)) {
|
||||
return mod.default;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function getProjectHero(project: Project): ImageMetadata {
|
||||
let image: ImageMetadata = Object.values(allProjectHeros)[0].default;
|
||||
for (const [path, mod] of Object.entries(allProjectHeros)) {
|
||||
@@ -110,3 +127,13 @@ export async function getFullExternalURLOfImage(
|
||||
return new URL((await getImage({ src: image })).src, import.meta.env.SITE)
|
||||
.href;
|
||||
}
|
||||
|
||||
export function slugify(input: string): string {
|
||||
if (!input) return "";
|
||||
let slug = input.toLowerCase().trim();
|
||||
slug = slug.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||
slug = slug.replace(/[^a-z0-9\s-]/g, " ");
|
||||
slug = slug.replace(/[\s-]+/g, "-");
|
||||
slug = slug.replace(/^-+|-+$/g, "");
|
||||
return slug;
|
||||
}
|
||||
|
Reference in New Issue
Block a user