From 707d817ff4d008bd4de069eaa079b634b8b0b454 Mon Sep 17 00:00:00 2001 From: Guido X Jansen Date: Fri, 20 Dec 2024 09:46:12 +0100 Subject: [PATCH] Frontend fix --- .gitignore | 3 + migrate-images.mjs | 63 ++++++++++++++++++ src/components/FreelancerCard.astro | 4 +- .../freelancers/Andrey Lidokhover.yaml | 2 +- .../freelancers/Constantin Iordan.yaml | 2 +- src/content/freelancers/David Greiner.yaml | 2 +- src/content/freelancers/Evgeny Nekhamkin.yaml | 2 +- src/content/freelancers/Filip Galic.yaml | 2 +- src/content/freelancers/Ivan Jurisic.yaml | 2 +- src/content/freelancers/Jan Kovacs.yaml | 2 +- src/content/freelancers/Javier Benito.yaml | 2 +- src/content/freelancers/Vasily Rodin.yaml | 2 +- .../freelancers/Volodymyr Rychenko.yaml | 2 +- .../photo.jpg} | 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 | 4 +- update-paths.mjs | 38 +++++++++++ 25 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 migrate-images.mjs rename src/images/freelancers/{andrey-lidokhover.jpg => andrey-lidokhover/photo.jpg} (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%) create mode 100644 update-paths.mjs diff --git a/.gitignore b/.gitignore index 2697a4b..e3f95fd 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ pnpm-debug.log* # macOS-specific files .DS_Store + +# CLine instructions +.clinerules \ No newline at end of file diff --git a/migrate-images.mjs b/migrate-images.mjs new file mode 100644 index 0000000..3ea93df --- /dev/null +++ b/migrate-images.mjs @@ -0,0 +1,63 @@ +import fs from 'fs/promises'; +import path from 'path'; + +const FREELANCERS_CONTENT_DIR = 'src/content/freelancers'; +const FREELANCERS_IMAGES_DIR = 'src/images/freelancers'; + +async function migrateImages() { + try { + // Get all freelancer YAML files + const files = await fs.readdir(FREELANCERS_CONTENT_DIR); + const yamlFiles = files.filter(file => file.endsWith('.yaml')); + + for (const yamlFile of yamlFiles) { + // Skip the new format file + if (yamlFile === 'onofrei-andrei-codrut.yaml') continue; + + // Read YAML content + const yamlPath = path.join(FREELANCERS_CONTENT_DIR, yamlFile); + const content = await fs.readFile(yamlPath, 'utf8'); + + // Extract current photo path + const photoMatch = content.match(/photo: (.+\.jpe?g)/); + if (!photoMatch) { + console.log(`No photo found in ${yamlFile}`); + continue; + } + + const oldPhotoName = photoMatch[1]; + const oldPhotoPath = path.join(FREELANCERS_IMAGES_DIR, oldPhotoName); + + // Create new directory name from YAML filename (without extension) + const dirName = yamlFile.replace('.yaml', '').toLowerCase().replace(/ /g, '-'); + const newDirPath = path.join(FREELANCERS_IMAGES_DIR, dirName); + + // Create new directory + await fs.mkdir(newDirPath, { recursive: true }); + + // Get file extension from original image + const ext = path.extname(oldPhotoName); + const newPhotoPath = path.join(newDirPath, `photo${ext}`); + + // Move and rename the image + await fs.rename(oldPhotoPath, newPhotoPath); + + // Update YAML content with new photo path + const newContent = content.replace( + /photo: .+/, + `photo: "${dirName}/photo${ext}"` + ); + + // Write updated YAML + await fs.writeFile(yamlPath, newContent, 'utf8'); + + console.log(`Migrated ${yamlFile} and its image`); + } + + console.log('Migration completed successfully'); + } catch (error) { + console.error('Migration failed:', error); + } +} + +migrateImages(); diff --git a/src/components/FreelancerCard.astro b/src/components/FreelancerCard.astro index a38df16..434bd1c 100644 --- a/src/components/FreelancerCard.astro +++ b/src/components/FreelancerCard.astro @@ -20,7 +20,7 @@ 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' }); @@ -40,7 +40,7 @@ async function getFreelancerImage(photoPath: string) { const freelancerSlug = generateNameSlug(freelancer.firstName, freelancer.lastName); // Construct the correct image path -const imagePath = `/src/images/freelancers/${freelancer.photo}`; +const imagePath = freelancer.photo; // Get the image from our glob with type checking const freelancerImage: ImageMetadata | undefined = imageFiles[imagePath]; diff --git a/src/content/freelancers/Andrey Lidokhover.yaml b/src/content/freelancers/Andrey Lidokhover.yaml index 6df1f85..3faf3ef 100644 --- a/src/content/freelancers/Andrey Lidokhover.yaml +++ b/src/content/freelancers/Andrey Lidokhover.yaml @@ -1,6 +1,6 @@ firstName: Andrey lastName: Lidokhover -photo: andrey-lidokhover.jpg +photo: /src/images/freelancers/andrey-lidokhover/photo.jpg headline: Senior Spryker Backend Developer availability: November 2024, fulltime location: Hamburg diff --git a/src/content/freelancers/Constantin Iordan.yaml b/src/content/freelancers/Constantin Iordan.yaml index 51097b4..9f99736 100644 --- a/src/content/freelancers/Constantin Iordan.yaml +++ b/src/content/freelancers/Constantin Iordan.yaml @@ -1,6 +1,6 @@ firstName: Constantin lastName: Iordan -photo: Constantin-Iordan.jpg +photo: /src/images/freelancers/constantin-iordan/photo.jpg headline: Senior PHP Developer availability: January 2025, 8h/day, 5 days/week location: Brasov diff --git a/src/content/freelancers/David Greiner.yaml b/src/content/freelancers/David Greiner.yaml index 91d5458..dda6fbf 100644 --- a/src/content/freelancers/David Greiner.yaml +++ b/src/content/freelancers/David Greiner.yaml @@ -1,6 +1,6 @@ firstName: David lastName: Greiner -photo: david_greiner_spryker_freelancer.jpg +photo: /src/images/freelancers/david-greiner/photo.jpg headline: Senior Spryker Backend Developer availability: Immediate location: Germany diff --git a/src/content/freelancers/Evgeny Nekhamkin.yaml b/src/content/freelancers/Evgeny Nekhamkin.yaml index f44a4b5..bd8d09e 100644 --- a/src/content/freelancers/Evgeny Nekhamkin.yaml +++ b/src/content/freelancers/Evgeny Nekhamkin.yaml @@ -1,6 +1,6 @@ firstName: Evgeny lastName: Nekhamkin -photo: evgeny-nekhamkin.jpg +photo: /src/images/freelancers/evgeny-nekhamkin/photo.jpg headline: Senior Webdeveloper & Architect availability: Mid October / 36-40 Hours location: Hamburg diff --git a/src/content/freelancers/Filip Galic.yaml b/src/content/freelancers/Filip Galic.yaml index 200ff9f..909cbc0 100644 --- a/src/content/freelancers/Filip Galic.yaml +++ b/src/content/freelancers/Filip Galic.yaml @@ -1,6 +1,6 @@ firstName: Filip lastName: Galic -photo: filip-galic.jpeg +photo: /src/images/freelancers/filip-galic/photo.jpeg headline: Spryker engineer availability: Immediately location: Bosnia and Herzegovina, Siroki Brijeg diff --git a/src/content/freelancers/Ivan Jurisic.yaml b/src/content/freelancers/Ivan Jurisic.yaml index d4f1744..061afce 100644 --- a/src/content/freelancers/Ivan Jurisic.yaml +++ b/src/content/freelancers/Ivan Jurisic.yaml @@ -1,6 +1,6 @@ firstName: Ivan lastName: Jurisic -photo: ivan-jurisic.jpg +photo: /src/images/freelancers/ivan-jurisic/photo.jpg headline: Spryker developer availability: Immediately location: Makarska, Croatia diff --git a/src/content/freelancers/Jan Kovacs.yaml b/src/content/freelancers/Jan Kovacs.yaml index 73517c4..433d29c 100644 --- a/src/content/freelancers/Jan Kovacs.yaml +++ b/src/content/freelancers/Jan Kovacs.yaml @@ -1,6 +1,6 @@ firstName: Jan lastName: Kovács -photo: jan-kovacs.jpg +photo: /src/images/freelancers/jan-kovacs/photo.jpg headline: Experienced Software Engineer & Leader availability: November 2024, 40 hours/week location: Hamburg diff --git a/src/content/freelancers/Javier Benito.yaml b/src/content/freelancers/Javier Benito.yaml index 6bbd0aa..341f8a0 100644 --- a/src/content/freelancers/Javier Benito.yaml +++ b/src/content/freelancers/Javier Benito.yaml @@ -1,6 +1,6 @@ firstName: Javier lastName: Benito -photo: javier-benito.jpg +photo: /src/images/freelancers/javier-benito/photo.jpg headline: Senior Software Engineer availability: Immediately location: Madrid diff --git a/src/content/freelancers/Vasily Rodin.yaml b/src/content/freelancers/Vasily Rodin.yaml index c4e9819..0e98212 100644 --- a/src/content/freelancers/Vasily Rodin.yaml +++ b/src/content/freelancers/Vasily Rodin.yaml @@ -1,6 +1,6 @@ firstName: Vasily lastName: Rodin -photo: vasily-rodin.jpg +photo: /src/images/freelancers/vasily-rodin/photo.jpg headline: Senior Spryker Developer & Tech Lead availability: 2025, usually 8h per day location: Berlin diff --git a/src/content/freelancers/Volodymyr Rychenko.yaml b/src/content/freelancers/Volodymyr Rychenko.yaml index ee9558e..d877c4d 100644 --- a/src/content/freelancers/Volodymyr Rychenko.yaml +++ b/src/content/freelancers/Volodymyr Rychenko.yaml @@ -1,6 +1,6 @@ firstName: Volodymyr lastName: Hrychenko -photo: volodymyr-rychenko.jpg +photo: /src/images/freelancers/volodymyr-rychenko/photo.jpg headline: Spryker Developer & Solution Architect availability: Fulltime location: Warsaw diff --git a/src/images/freelancers/andrey-lidokhover.jpg b/src/images/freelancers/andrey-lidokhover/photo.jpg similarity index 100% rename from src/images/freelancers/andrey-lidokhover.jpg rename to src/images/freelancers/andrey-lidokhover/photo.jpg diff --git a/src/images/freelancers/Constantin-Iordan.jpg b/src/images/freelancers/constantin-iordan/photo.jpg similarity index 100% rename from src/images/freelancers/Constantin-Iordan.jpg rename to src/images/freelancers/constantin-iordan/photo.jpg diff --git a/src/images/freelancers/david_greiner_spryker_freelancer.jpg b/src/images/freelancers/david-greiner/photo.jpg similarity index 100% rename from src/images/freelancers/david_greiner_spryker_freelancer.jpg rename to src/images/freelancers/david-greiner/photo.jpg diff --git a/src/images/freelancers/evgeny-nekhamkin.jpg b/src/images/freelancers/evgeny-nekhamkin/photo.jpg similarity index 100% rename from src/images/freelancers/evgeny-nekhamkin.jpg rename to src/images/freelancers/evgeny-nekhamkin/photo.jpg diff --git a/src/images/freelancers/filip-galic.jpeg b/src/images/freelancers/filip-galic/photo.jpeg similarity index 100% rename from src/images/freelancers/filip-galic.jpeg rename to src/images/freelancers/filip-galic/photo.jpeg diff --git a/src/images/freelancers/ivan-jurisic.jpg b/src/images/freelancers/ivan-jurisic/photo.jpg similarity index 100% rename from src/images/freelancers/ivan-jurisic.jpg rename to src/images/freelancers/ivan-jurisic/photo.jpg diff --git a/src/images/freelancers/jan-kovacs.jpg b/src/images/freelancers/jan-kovacs/photo.jpg similarity index 100% rename from src/images/freelancers/jan-kovacs.jpg rename to src/images/freelancers/jan-kovacs/photo.jpg diff --git a/src/images/freelancers/javier-benito.jpg b/src/images/freelancers/javier-benito/photo.jpg similarity index 100% rename from src/images/freelancers/javier-benito.jpg rename to src/images/freelancers/javier-benito/photo.jpg diff --git a/src/images/freelancers/vasily-rodin.jpg b/src/images/freelancers/vasily-rodin/photo.jpg similarity index 100% rename from src/images/freelancers/vasily-rodin.jpg rename to src/images/freelancers/vasily-rodin/photo.jpg diff --git a/src/images/freelancers/volodymyr-rychenko.jpg b/src/images/freelancers/volodymyr-rychenko/photo.jpg similarity index 100% rename from src/images/freelancers/volodymyr-rychenko.jpg rename to src/images/freelancers/volodymyr-rychenko/photo.jpg diff --git a/src/pages/jobs/[slug].astro b/src/pages/jobs/[slug].astro index e7780ec..64bbb96 100644 --- a/src/pages/jobs/[slug].astro +++ b/src/pages/jobs/[slug].astro @@ -13,7 +13,7 @@ import keystaticConfig from '../../../keystatic.config'; import type { Freelancer, KeystaticFreelancer } from '../../types.ts'; // 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' }); @@ -61,7 +61,7 @@ const pageTitle = `${`${freelancer.firstName} ${freelancer.lastName}`} - Spryker const hasCertifications = hasSprykerCertifications(freelancer.sprykerCertifications); // Construct the correct image path -const imagePath = `/src/images/freelancers/${freelancer.photo}`; +const imagePath = freelancer.photo; // Get the image from our glob const freelancerImage: ImageMetadata | undefined = imageFiles[imagePath]; diff --git a/update-paths.mjs b/update-paths.mjs new file mode 100644 index 0000000..457ce4b --- /dev/null +++ b/update-paths.mjs @@ -0,0 +1,38 @@ +import fs from 'fs/promises'; +import path from 'path'; + +const FREELANCERS_CONTENT_DIR = 'src/content/freelancers'; + +async function updatePaths() { + try { + // Get all freelancer YAML files + const files = await fs.readdir(FREELANCERS_CONTENT_DIR); + const yamlFiles = files.filter(file => file.endsWith('.yaml')); + + for (const yamlFile of yamlFiles) { + // Skip the new format file + if (yamlFile === 'onofrei-andrei-codrut.yaml') continue; + + // Read YAML content + const yamlPath = path.join(FREELANCERS_CONTENT_DIR, yamlFile); + const content = await fs.readFile(yamlPath, 'utf8'); + + // Update photo path to include /src prefix + const newContent = content.replace( + /photo: "([^"]+)"/, + 'photo: /src/images/freelancers/$1' + ); + + // Write updated YAML + await fs.writeFile(yamlPath, newContent, 'utf8'); + + console.log(`Updated path in ${yamlFile}`); + } + + console.log('Path updates completed successfully'); + } catch (error) { + console.error('Update failed:', error); + } +} + +updatePaths();