From 0c421b66c073b523dbcb993054d902d0332cada4 Mon Sep 17 00:00:00 2001 From: dante01yoon Date: Sun, 29 Mar 2026 12:40:05 +0900 Subject: [PATCH] fix: pass status filter to hub API in search index build build-index.ts was calling /api/hub/workflows/index without a ?status= parameter, while hub-api.ts listWorkflowIndex() passes explicit status filters. On the test API (used by preview builds), the default response without status filter returns no workflows, producing an empty search index. Production was unaffected because the prod API has approved workflows returned by default. Also fall back to content collection when the API returns an empty array instead of treating [] as a successful result. --- site/scripts/lib/search/build-index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/site/scripts/lib/search/build-index.ts b/site/scripts/lib/search/build-index.ts index 342e1c9a8..6f3b0de1b 100644 --- a/site/scripts/lib/search/build-index.ts +++ b/site/scripts/lib/search/build-index.ts @@ -49,9 +49,18 @@ async function fetchIndexEntries(): Promise { const apiUrl = (process.env.PUBLIC_HUB_API_URL || '').replace(/\/$/, ''); if (!apiUrl) return null; try { - const res = await fetch(`${apiUrl}/api/hub/workflows/index`); + // Match hub-api.ts listWorkflowIndex(): preview builds request all statuses + // so the search index includes pending/rejected/deprecated workflows too. + // Production builds (PUBLIC_APPROVED_ONLY=true) request only approved. + const approvedOnly = process.env.PUBLIC_APPROVED_ONLY === 'true'; + const statuses = approvedOnly + ? 'approved' + : 'pending,approved,rejected,deprecated'; + const res = await fetch(`${apiUrl}/api/hub/workflows/index?status=${statuses}`); if (!res.ok) return null; - return (await res.json()) as IndexEntry[]; + const entries = (await res.json()) as IndexEntry[]; + // Return null on empty array so the caller falls back to content collection + return entries.length > 0 ? entries : null; } catch { return null; }