From ba5b2a7c0ff9143e1897392c9b1a7b1e9edbe9df Mon Sep 17 00:00:00 2001 From: Justin Bennett Date: Sun, 24 Nov 2024 19:06:30 -0500 Subject: [PATCH] Ensure tags aren't incorrectly split I published a meta tag and it was showing up as `/m/` instead of `/meta/`. --- 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}`; }