From afceefa24d310e3e9ab716e353ffd5c3e5688c16 Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Fri, 2 Aug 2024 05:28:35 -0700 Subject: [PATCH] Use "includes" instead of "indexOf" for strings --- src/components/elements/link.tsx | 8 +++++++- src/components/elements/slideshow.tsx | 4 ++-- src/components/elements/wysiwyg.tsx | 4 ++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/elements/link.tsx b/src/components/elements/link.tsx index 100abdba..35e3fc49 100644 --- a/src/components/elements/link.tsx +++ b/src/components/elements/link.tsx @@ -18,7 +18,13 @@ const DrupalLink = ({href, className, children, ...props}: Props) => { href = href || "#" const drupalBase: string = (process.env.NEXT_PUBLIC_DRUPAL_BASE_URL || "").replace(/\/$/, "") - if (!href.indexOf("/files/")) { + // Make sure links to documents or images go to the Drupal origin. + if (href.startsWith("/") && href.includes("/files/")) { + href = `${drupalBase}${href}` + } + + // For links not to the file system, make them relative and replace . + if (!href.includes("/files/")) { href = href.replace(drupalBase, "").replace("", "/") } diff --git a/src/components/elements/slideshow.tsx b/src/components/elements/slideshow.tsx index fd495b8d..b8cd1c47 100644 --- a/src/components/elements/slideshow.tsx +++ b/src/components/elements/slideshow.tsx @@ -7,7 +7,7 @@ import {twMerge} from "tailwind-merge" import {clsx} from "clsx" const NextArrow = ({className, onClick}: CustomArrowProps) => { - const slickDisabled = !!(className && className?.indexOf("slick-disabled") > 0) + const slickDisabled = className?.includes("slick-disabled") return (