From 6f1af1cef39e756e8826e4cdb2caa19dcc04e5ee Mon Sep 17 00:00:00 2001 From: Maria Juliana Arias Hernandez Date: Tue, 19 May 2026 00:40:10 -0700 Subject: [PATCH 1/2] fix(search): filter search results by docs version and show version badge --- src/components/Header/Docsearch/Component.tsx | 36 ++++++++++++++++--- .../Header/Docsearch/index.module.scss | 18 ++++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/components/Header/Docsearch/Component.tsx b/src/components/Header/Docsearch/Component.tsx index 1ff9ba360..fbe1b0001 100644 --- a/src/components/Header/Docsearch/Component.tsx +++ b/src/components/Header/Docsearch/Component.tsx @@ -4,15 +4,26 @@ import React from 'react' import classes from './index.module.scss' -function Hit({ children, hit, path }) { - const blog = hit?.url?.includes('/blog/') || false +function getVersionedUrl(url: string, path: string): string { + if (!url) return url + + const isV2 = path.includes('/docs/v2/') - let url = hit?.url + if (isV2 && !url.includes('/docs/v2/')) { + return url.replace('/docs/', '/docs/v2/') + } - if (path.includes('/docs/v2/')) { - url = url.replace('/docs/', '/docs/v2/') + if (!isV2 && url.includes('/docs/v2/')) { + return url.replace('/docs/v2/', '/docs/') } + return url +} + +function Hit({ children, hit, path }: { children: React.ReactNode; hit: any; path: string }) { + const blog = hit?.url?.includes('/blog/') || false + const url = getVersionedUrl(hit?.url, path) + return ( {children} @@ -22,14 +33,29 @@ function Hit({ children, hit, path }) { function Component() { const path = usePathname() + const isV2 = path.includes('/docs/v2/') return ( +
Hit({ children, hit, path })} indexName="payloadcms" + searchParameters={ + isV2 + ? { facetFilters: ['version:v2'] } + : { facetFilters: ['version:v3'] } + } /> + {isV2 && ( +
+ Searching in v2 docs +
+ )} +
) } + + export default Component diff --git a/src/components/Header/Docsearch/index.module.scss b/src/components/Header/Docsearch/index.module.scss index 536cb0b4f..c64ca14e2 100644 --- a/src/components/Header/Docsearch/index.module.scss +++ b/src/components/Header/Docsearch/index.module.scss @@ -30,5 +30,23 @@ & svg { display: none; } + + .searchWrapper { + position: relative; + } + + .versionBadge { + position: absolute; + top: -8px; + right: -4px; + background-color: #f59e0b; + color: #000; + font-size: 10px; + font-weight: 600; + padding: 2px 6px; + border-radius: 4px; + pointer-events: none; + white-space: nowrap; + } } } From 7be8de272948fc75e22ccdd57b93f18cc5d442c7 Mon Sep 17 00:00:00 2001 From: Maria Juliana Arias Hernandez Date: Tue, 19 May 2026 01:37:37 -0700 Subject: [PATCH 2/2] fix(search): show version badge for both v2 and v3 --- src/components/Header/Docsearch/Component.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Header/Docsearch/Component.tsx b/src/components/Header/Docsearch/Component.tsx index fbe1b0001..6bb822f3c 100644 --- a/src/components/Header/Docsearch/Component.tsx +++ b/src/components/Header/Docsearch/Component.tsx @@ -49,7 +49,7 @@ function Component() { /> {isV2 && (
- Searching in v2 docs + {isV2 ? 'Searching in v2 docs' : 'Searching in v3 docs'}
)}