diff --git a/src/marketing/next-shims.test.ts b/src/marketing/next-shims.test.ts index e834c56c..f4e17954 100644 --- a/src/marketing/next-shims.test.ts +++ b/src/marketing/next-shims.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { isClientRoutedBlogHref } from './next-shims' +import { isClientRoutedBlogHref, normalizeMarketingPathname } from './next-shims' describe('isClientRoutedBlogHref', () => { it.each([ @@ -22,3 +22,16 @@ describe('isClientRoutedBlogHref', () => { expect(isClientRoutedBlogHref(href)).toBe(true) }) }) + +describe('normalizeMarketingPathname', () => { + it.each([ + ['/developers', '/'], + ['/developers/', '/'], + ['/developers/build', '/build'], + ['/developers/blog/t7-network-upgrade', '/blog/t7-network-upgrade'], + ['/', '/'], + ['/blog', '/blog'], + ])('normalizes %s to %s', (pathname, expected) => { + expect(normalizeMarketingPathname(pathname)).toBe(expected) + }) +}) diff --git a/src/marketing/next-shims.tsx b/src/marketing/next-shims.tsx index 9a885d8b..0d0df83b 100644 --- a/src/marketing/next-shims.tsx +++ b/src/marketing/next-shims.tsx @@ -92,8 +92,14 @@ export function Image({ priority: _priority, fill: _fill, alt, ...props }: Image return {alt} } +export function normalizeMarketingPathname(pathname: string) { + if (pathname === '/developers') return '/' + if (pathname.startsWith('/developers/')) return pathname.slice('/developers'.length) + return pathname +} + export function usePathname() { - return typeof window === 'undefined' ? '/' : window.location.pathname + return typeof window === 'undefined' ? '/' : normalizeMarketingPathname(window.location.pathname) } export function notFound(): never {