From a4fa9b42fa0c99b29ca4ad60091739315a1ccd2e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 23 Jan 2026 02:17:01 +0000 Subject: [PATCH] Fix JSON parsing for tags and technologies arrays from Directus Co-authored-by: denshooter <44590296+denshooter@users.noreply.github.com> --- lib/directus.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/directus.ts b/lib/directus.ts index de55d87..7abe337 100644 --- a/lib/directus.ts +++ b/lib/directus.ts @@ -549,6 +549,21 @@ export async function getProjects( proj.translations?.find((t: any) => t.languages_code?.code === directusLocale) || proj.translations?.[0] || {}; + + // Parse JSON string fields if needed + const parseTags = (tags: any) => { + if (!tags) return []; + if (Array.isArray(tags)) return tags; + if (typeof tags === 'string') { + try { + return JSON.parse(tags); + } catch { + return []; + } + } + return []; + }; + return { id: proj.id, slug: proj.slug, @@ -557,8 +572,8 @@ export async function getProjects( content: trans.content, category: proj.category, difficulty: proj.difficulty, - tags: proj.tags || [], - technologies: proj.technologies || [], + tags: parseTags(proj.tags), + technologies: parseTags(proj.technologies), challenges: proj.challenges, lessons_learned: proj.lessons_learned, future_improvements: proj.future_improvements, @@ -567,7 +582,7 @@ export async function getProjects( image_url: proj.image_url, demo_video_url: proj.demo_video, performance_metrics: proj.performance_metrics, - screenshots: proj.screenshots || [], + screenshots: parseTags(proj.screenshots), featured: proj.featured === 1 || proj.featured === true, published: proj.status === 'published', created_at: proj.date_created,