mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 12:47:50 +00:00
Added the util function to remove the domian part of the url
This commit is contained in:
parent
887d437795
commit
8cd637e609
@ -2,6 +2,7 @@
|
||||
|
||||
import clsx from 'clsx';
|
||||
import { Menu } from 'lib/shopify/types';
|
||||
import { RemoveTheDomainFromUrl } from 'lib/utils';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import { useEffect, useState } from 'react';
|
||||
@ -17,7 +18,7 @@ const FooterMenuItem = ({ item }: { item: Menu }) => {
|
||||
return (
|
||||
<li>
|
||||
<Link
|
||||
href={item.path}
|
||||
href={RemoveTheDomainFromUrl(item.path)}
|
||||
className={clsx(
|
||||
'block p-2 text-lg underline-offset-4 hover:text-black hover:underline md:inline-block md:text-sm dark:hover:text-neutral-300',
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ import OpenCart from 'components/cart/open-cart';
|
||||
import LogoSquare from 'components/logo-square';
|
||||
import { getMenu } from 'lib/shopify';
|
||||
import { Menu } from 'lib/shopify/types';
|
||||
import { RemoveTheDomainFromUrl } from 'lib/utils';
|
||||
import Link from 'next/link';
|
||||
import { Suspense } from 'react';
|
||||
import MobileMenu from './mobile-menu';
|
||||
@ -32,7 +33,7 @@ export default async function Navbar() {
|
||||
{menu.map((item: Menu) => (
|
||||
<li key={item.title}>
|
||||
<Link
|
||||
href={item.path}
|
||||
href={RemoveTheDomainFromUrl(item.path)}
|
||||
className="text-neutral-500 underline-offset-4 hover:text-black hover:underline dark:text-neutral-400 dark:hover:text-neutral-300"
|
||||
>
|
||||
{item.title}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { ReadonlyURLSearchParams } from 'next/navigation';
|
||||
const { SHOPIFY_STORE_DOMAIN } = process.env;
|
||||
|
||||
export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyURLSearchParams) => {
|
||||
const paramsString = params.toString();
|
||||
@ -7,6 +8,13 @@ export const createUrl = (pathname: string, params: URLSearchParams | ReadonlyUR
|
||||
return `${pathname}${queryString}`;
|
||||
};
|
||||
|
||||
export const RemoveTheDomainFromUrl = (url: string) => {
|
||||
const lowercaseString = `https://${SHOPIFY_STORE_DOMAIN}`.toLowerCase();
|
||||
const modifiedUrl = url.replace(lowercaseString, '');
|
||||
|
||||
return modifiedUrl;
|
||||
};
|
||||
|
||||
export const ensureStartsWith = (stringToCheck: string, startsWith: string) =>
|
||||
stringToCheck.startsWith(startsWith) ? stringToCheck : `${startsWith}${stringToCheck}`;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user