|
1 | 1 | import React from "react"; |
| 2 | +import { Link } from "gatsby"; |
2 | 3 | import { HiOutlineChevronRight } from "@react-icons/all-files/hi/HiOutlineChevronRight"; |
3 | 4 | import { AdventuresVolWrapper } from "./adventures-vol.style"; |
4 | 5 |
|
5 | 6 | const AdventuresVol = ({ title, description, to, image }) => { |
| 7 | + const isExternalOrStatic = |
| 8 | + to && |
| 9 | + (to.startsWith("http://") || |
| 10 | + to.startsWith("https://") || |
| 11 | + to.split("?")[0].split("#")[0].toLowerCase().endsWith(".pdf") || |
| 12 | + to.startsWith("mailto:")); |
| 13 | + |
| 14 | + const isMailTo = to && to.startsWith("mailto:"); |
| 15 | + |
| 16 | + const cardContent = ( |
| 17 | + <div className="handbook__card"> |
| 18 | + <h1 className="handbook__card--head">{title}</h1> |
| 19 | + <div className="handbook__card--line"></div> |
| 20 | + <img src={image} /> |
| 21 | + <p className="handbook__card--para">{description}</p> |
| 22 | + {to && ( |
| 23 | + <div className="handbook__card--lm__container"> |
| 24 | + <span className="handbook__card--lm"> |
| 25 | + Read More <HiOutlineChevronRight /> |
| 26 | + </span> |
| 27 | + </div> |
| 28 | + )} |
| 29 | + </div> |
| 30 | + ); |
| 31 | + |
6 | 32 | return ( |
7 | 33 | <AdventuresVolWrapper> |
8 | | - <a href={to} className="handbook__card--main"> |
9 | | - <div className="handbook__card"> |
10 | | - <h1 className="handbook__card--head">{title}</h1> |
11 | | - <div className="handbook__card--line"></div> |
12 | | - <img src={image} /> |
13 | | - <p className="handbook__card--para"> |
14 | | - {description} |
15 | | - </p> |
16 | | - {to && ( |
17 | | - <div className="handbook__card--lm__container"> |
18 | | - <a href={to} className="handbook__card--lm"> |
19 | | - Read More <HiOutlineChevronRight /> |
20 | | - </a> |
21 | | - </div> |
22 | | - )} |
23 | | - </div> |
24 | | - </a> |
| 34 | + {!to ? ( |
| 35 | + <div className="handbook__card--main">{cardContent}</div> |
| 36 | + ) : isExternalOrStatic ? ( |
| 37 | + <a |
| 38 | + href={to} |
| 39 | + className="handbook__card--main" |
| 40 | + target={isMailTo ? undefined : "_blank"} |
| 41 | + rel={isMailTo ? undefined : "noreferrer"} |
| 42 | + > |
| 43 | + {cardContent} |
| 44 | + </a> |
| 45 | + ) : ( |
| 46 | + <Link to={to} className="handbook__card--main"> |
| 47 | + {cardContent} |
| 48 | + </Link> |
| 49 | + )} |
25 | 50 | </AdventuresVolWrapper> |
26 | 51 | ); |
27 | 52 | }; |
|
0 commit comments