From 4f459ffaedd9fe92a5e1a404a061a1fb160207d9 Mon Sep 17 00:00:00 2001 From: Justin Bennett Date: Mon, 16 Dec 2024 11:22:25 -0800 Subject: [PATCH] Ensure tags aren't incorrectly split (#103) --- src/pages/api/[...path].ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/api/[...path].ts b/src/pages/api/[...path].ts index 3fe3f25..20eff97 100644 --- a/src/pages/api/[...path].ts +++ b/src/pages/api/[...path].ts @@ -34,11 +34,12 @@ const app = new Hono<{ Bindings: AstroContext }>() throw new Error("Title and H1s should not be a ULID"); } - const primaryTag = props.tags?.split(",")[0]; + const tags = props.tags?.split(",").filter(Boolean) ?? []; + const primaryTag = tags[0]; // Set the prefix URL to the first tag (or its mapped value) if it exists if (primaryTag && primaryTag !== slug) { slug = `${ - tagMap[primaryTag as keyof typeof tagMap] ?? props.tags[0] + tagMap[primaryTag as keyof typeof tagMap] ?? primaryTag }/${slug}`; }