From d836d4a7006a1689ae6f011181d230fe4b518243 Mon Sep 17 00:00:00 2001 From: Florian Schwarzmeier Date: Fri, 20 Dec 2024 17:38:15 +0100 Subject: [PATCH] Fixes freelancer photo usage for keystatic (#205) --- keystatic.config.ts | 23 ++++++------------ src/components/FreelancerCard.astro | 18 ++------------ ...Lidokhover.yaml => andrey-lidokhover.yaml} | 2 +- ...andrei-codrut.yaml => codrut-onofrei.yaml} | 4 +-- ...tin Iordan.yaml => constantin-iordan.yaml} | 2 +- ...{David Greiner.yaml => david-greiner.yaml} | 2 +- ...y Nekhamkin.yaml => evgeny-nekhamkin.yaml} | 2 +- .../{Filip Galic.yaml => filip-galic.yaml} | 2 +- .../{Ivan Jurisic.yaml => ivan-jurisic.yaml} | 2 +- .../{Jan Kovacs.yaml => jan-kovacs.yaml} | 2 +- ...{Javier Benito.yaml => javier-benito.yaml} | 2 +- .../{Vasily Rodin.yaml => vasily-rodin.yaml} | 2 +- ... Rychenko.yaml => volodymyr-rychenko.yaml} | 2 +- .../photo.jpg} | Bin .../photo.jpeg | Bin .../photo.jpg} | Bin .../photo.jpg} | Bin .../photo.jpg} | Bin .../photo.jpeg} | Bin .../photo.jpg} | Bin .../{jan-kovacs.jpg => jan-kovacs/photo.jpg} | Bin .../photo.jpg} | Bin .../photo.jpg} | Bin .../photo.jpg} | Bin src/pages/jobs/[slug].astro | 7 ++---- 25 files changed, 23 insertions(+), 49 deletions(-) rename src/content/freelancers/{Andrey Lidokhover.yaml => andrey-lidokhover.yaml} (96%) rename src/content/freelancers/{onofrei-andrei-codrut.yaml => codrut-onofrei.yaml} (91%) rename src/content/freelancers/{Constantin Iordan.yaml => constantin-iordan.yaml} (98%) rename src/content/freelancers/{David Greiner.yaml => david-greiner.yaml} (97%) rename src/content/freelancers/{Evgeny Nekhamkin.yaml => evgeny-nekhamkin.yaml} (95%) rename src/content/freelancers/{Filip Galic.yaml => filip-galic.yaml} (96%) rename src/content/freelancers/{Ivan Jurisic.yaml => ivan-jurisic.yaml} (96%) rename src/content/freelancers/{Jan Kovacs.yaml => jan-kovacs.yaml} (96%) rename src/content/freelancers/{Javier Benito.yaml => javier-benito.yaml} (97%) rename src/content/freelancers/{Vasily Rodin.yaml => vasily-rodin.yaml} (95%) rename src/content/freelancers/{Volodymyr Rychenko.yaml => volodymyr-rychenko.yaml} (97%) rename src/images/freelancers/{andrey-lidokhover.jpg => andrey-lidokhover/photo.jpg} (100%) rename src/images/freelancers/{onofrei-andrei-codrut => codrut-onofrei}/photo.jpeg (100%) rename src/images/freelancers/{Constantin-Iordan.jpg => constantin-iordan/photo.jpg} (100%) rename src/images/freelancers/{david_greiner_spryker_freelancer.jpg => david-greiner/photo.jpg} (100%) rename src/images/freelancers/{evgeny-nekhamkin.jpg => evgeny-nekhamkin/photo.jpg} (100%) rename src/images/freelancers/{filip-galic.jpeg => filip-galic/photo.jpeg} (100%) rename src/images/freelancers/{ivan-jurisic.jpg => ivan-jurisic/photo.jpg} (100%) rename src/images/freelancers/{jan-kovacs.jpg => jan-kovacs/photo.jpg} (100%) rename src/images/freelancers/{javier-benito.jpg => javier-benito/photo.jpg} (100%) rename src/images/freelancers/{vasily-rodin.jpg => vasily-rodin/photo.jpg} (100%) rename src/images/freelancers/{volodymyr-rychenko.jpg => volodymyr-rychenko/photo.jpg} (100%) diff --git a/keystatic.config.ts b/keystatic.config.ts index baee56c..46e65e8 100644 --- a/keystatic.config.ts +++ b/keystatic.config.ts @@ -31,7 +31,13 @@ const keystaticConfig: Config = { }), slug: fields.text({ label: "Slug", - validation: { length: { min: 1 } } + validation: { + length: { min: 1 }, + pattern: { + regex: /^[a-z0-9-]+$/, + message: 'Please provide alphanumeric characters in lowercase and `-`.', + } + } }), photo: fields.image({ label: "Photo", @@ -233,19 +239,4 @@ const keystaticConfig: Config = { }), }, }; -/* - - "creators": [{"name": "Valantic", "url": "https://github.com/valantic-CEC-Deutschland-GmbH"}], - "contributors": [], - "links": [ - { - "label": "JetBrains marketplace", - "url": "https://plugins.jetbrains.com/plugin/18766-sprykerkit" - }, - { - "label": "Github", - "url": "https://github.com/valantic-CEC-Deutschland-GmbH/spryker-kit-intellij-plugin" - } - ] -*/ export default keystaticConfig; diff --git a/src/components/FreelancerCard.astro b/src/components/FreelancerCard.astro index a38df16..7c6acef 100644 --- a/src/components/FreelancerCard.astro +++ b/src/components/FreelancerCard.astro @@ -20,30 +20,16 @@ type Skill = string; const hasCertifications = hasSprykerCertifications(freelancer.sprykerCertifications); // Import all images at build time with proper typing -const imageFiles: Record = import.meta.glob('/src/images/freelancers/*.{jpeg,jpg,png,gif}', { +const imageFiles: Record = import.meta.glob('/src/images/freelancers/**/*.{jpeg,jpg,png,gif}', { eager: true, import: 'default' }); -// Add image import utility function -async function getFreelancerImage(photoPath: string) { - try { - const imageModule = await import(/* @vite-ignore */ `../images/freelancers/${photoPath}`); - return imageModule.default; - } catch (error) { - console.error(`Error loading image for ${photoPath}:`, error); - return null; - } -} - // Generate the URL-friendly slug for the freelancer const freelancerSlug = generateNameSlug(freelancer.firstName, freelancer.lastName); -// Construct the correct image path -const imagePath = `/src/images/freelancers/${freelancer.photo}`; - // Get the image from our glob with type checking -const freelancerImage: ImageMetadata | undefined = imageFiles[imagePath]; +const freelancerImage: ImageMetadata | undefined = imageFiles[freelancer.photo]; ---