Skip to content

Commit

Permalink
Use "includes" instead of "indexOf" for strings
Browse files Browse the repository at this point in the history
  • Loading branch information
pookmish committed Aug 2, 2024
1 parent 4c0eee2 commit afceefa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/components/elements/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 <front>.
if (!href.includes("/files/")) {
href = href.replace(drupalBase, "").replace("<front>", "/")
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/elements/slideshow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<button className="absolute right-1 top-1/3 z-50" onClick={onClick} aria-label="Next" disabled={slickDisabled}>
<ArrowRightIcon
Expand All @@ -18,7 +18,7 @@ const NextArrow = ({className, onClick}: CustomArrowProps) => {
}

const PrevArrow = ({className, onClick}: CustomArrowProps) => {
const slickDisabled = !!(className && className?.indexOf("slick-disabled") > 0)
const slickDisabled = className?.includes("slick-disabled")
return (
<button className="absolute left-1 top-1/3 z-50" onClick={onClick} aria-label="Previous" disabled={slickDisabled}>
<ArrowLeftIcon
Expand Down
4 changes: 2 additions & 2 deletions src/components/elements/wysiwyg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const options: HTMLReactParserOptions = {

case "div":
delete nodeProps.role
if (nodeProps.className && !!nodeProps.className.indexOf("media-entity-wrapper")) {
if (nodeProps.className?.includes("media-entity-wrapper")) {
return cleanMediaMarkup(domNode)
}
return <NodeName {...nodeProps}>{domToReact(children, options)}</NodeName>
Expand Down Expand Up @@ -216,7 +216,7 @@ const cleanMediaMarkup = (node: Element) => {

if (figCaption) {
nodeProps.className = twMerge("table", nodeProps.className)
if (!!nodeProps.className?.indexOf("mx-auto")) nodeProps.className += " w-full"
if (nodeProps.className?.includes("mx-auto")) nodeProps.className += " w-full"
delete nodeProps.role
return (
<figure {...nodeProps}>
Expand Down

0 comments on commit afceefa

Please sign in to comment.