From 5f0123334e85a91be114624a5375e25d18d23103 Mon Sep 17 00:00:00 2001 From: "Malin J." Date: Mon, 2 Dec 2024 09:55:20 +0100 Subject: [PATCH] remove breadcrumbs from pagecomponents #2604 --- web/pageComponents/topicPages/Breadcrumbs.tsx | 95 ------------------- 1 file changed, 95 deletions(-) delete mode 100644 web/pageComponents/topicPages/Breadcrumbs.tsx diff --git a/web/pageComponents/topicPages/Breadcrumbs.tsx b/web/pageComponents/topicPages/Breadcrumbs.tsx deleted file mode 100644 index 6ff81a771..000000000 --- a/web/pageComponents/topicPages/Breadcrumbs.tsx +++ /dev/null @@ -1,95 +0,0 @@ -import { default as NextLink } from 'next/link' -import { BreadcrumbsList } from '@core/Breadcrumbs' -import { BackgroundContainer, BackgroundContainerProps } from '@components' -import { BreadcrumbJsonLd } from 'next-seo' -import { useRouter } from 'next/router' -import type { NextRouter } from 'next/router' -import { getFullUrl } from '../../common/helpers/getFullUrl' -import { Breadcrumb } from '../../types' -import { twMerge } from 'tailwind-merge' - -const { BreadcrumbsListItem } = BreadcrumbsList - -type BreadcrumbsProps = { - slug: string - useCustomBreadcrumbs: boolean - defaultBreadcrumbs: Breadcrumb[] - customBreadcrumbs: Breadcrumb[] - className?: string -} & BackgroundContainerProps - -const buildJsonLdElements = (crumbs: Breadcrumb[], router: NextRouter) => { - const { pathname, locale } = router - - return crumbs.map((item, index) => { - const fullUrl = getFullUrl(pathname, item.slug, locale) - - return { - position: index + 1, - name: item.label, - item: fullUrl, - } - }) -} - -const parseSlug = (item: string): string => { - const parts = item?.split('/').at(-1) || item - return parts?.[0] + parts?.slice(1) -} - -const capitalize = (string: string): string => string[0].toUpperCase() + string.slice(1) - -const parseBreadcrumbs = (crumbs: Breadcrumb[]) => { - return crumbs - .filter((item) => item.slug && item.label) - .map((item) => ({ - ...item, - label: capitalize(item.label), - })) -} - -export const Breadcrumbs = ({ - slug, - useCustomBreadcrumbs, - defaultBreadcrumbs, - customBreadcrumbs, - background, - className = '', -}: BreadcrumbsProps) => { - const router = useRouter() - - const crumbs = - useCustomBreadcrumbs && customBreadcrumbs && customBreadcrumbs.length >= 3 - ? parseBreadcrumbs(customBreadcrumbs) - : parseBreadcrumbs(defaultBreadcrumbs) - - if (crumbs.length < 2) return null - - return ( - - - {crumbs.map((item: Breadcrumb) => { - const label = item.label ?? parseSlug(item.slug)?.replaceAll('-', ' ') - const shouldLink = item.slug !== slug - - return ( - - {shouldLink ? ( - - {label} - - ) : ( - <>{label} - )} - - ) - })} - - - - ) -}