mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
Normalize custom navigation url (#8)
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
parent
1cfca949ef
commit
eca79f89aa
@ -334,12 +334,21 @@ function normalizeLineItem(cartItemEdge: CartItemEdge): LineItem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const normalizeUrl = (url: string) => {
|
||||||
|
const splittedUrls = url.split('/')
|
||||||
|
return '/search/'.concat(splittedUrls.slice(2).join('/'))
|
||||||
|
}
|
||||||
|
|
||||||
export const normalizeNavigation = (
|
export const normalizeNavigation = (
|
||||||
navigationTreeItems: NavigationTreeItem[]
|
navigationTreeItems: NavigationTreeItem[]
|
||||||
): Navigation[] => {
|
): Navigation[] => {
|
||||||
return navigationTreeItems.map(({ items, navigationItem: { data } }) => {
|
return navigationTreeItems.map(({ items, navigationItem: { data } }) => {
|
||||||
|
const url = data?.url || '/'
|
||||||
|
const normalizedUrl =
|
||||||
|
data?.isUrlRelative && url.startsWith('/tag') ? normalizeUrl(url) : url
|
||||||
|
|
||||||
return {
|
return {
|
||||||
url: data?.url ?? '/',
|
url: normalizedUrl,
|
||||||
label: data?.contentForLanguage ?? 'N/A',
|
label: data?.contentForLanguage ?? 'N/A',
|
||||||
isUrlRelative: !!data?.isUrlRelative,
|
isUrlRelative: !!data?.isUrlRelative,
|
||||||
shouldOpenInNewWindow: !!data?.shouldOpenInNewWindow,
|
shouldOpenInNewWindow: !!data?.shouldOpenInNewWindow,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user