Skip to content

Commit 7427427

Browse files
Merge pull request #105 from niklasmtj/feature/internal-gatsby-links
feature: Use internal Link component
2 parents 3cb87fc + cfc92c6 commit 7427427

File tree

1 file changed

+36
-12
lines changed

1 file changed

+36
-12
lines changed

src/components/ui/banner.js

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
import { Link } from "gatsby"
12
import * as React from "react"
23

34
const Banner = ({ description, shortDescription, emoji, announcementLink }) => {
5+
const isExternalLink =
6+
announcementLink.indexOf("http://") === 0 ||
7+
announcementLink.indexOf("https://") === 0
8+
49
return (
510
<div className="bg-accent">
611
<div className="mx-auto max-w-7xl py-3 px-3 sm:px-6 lg:px-8">
@@ -9,18 +14,37 @@ const Banner = ({ description, shortDescription, emoji, announcementLink }) => {
914
{emoji && <span className="flex p-2 text-4xl">{emoji}</span>}
1015
<p className="ml-3 truncate font-bold text-2xl text-night">
1116
{announcementLink ? (
12-
<>
13-
<a
14-
href={announcementLink}
15-
className="md:hidden hover:underline hover:text-night">
16-
{shortDescription}
17-
</a>
18-
<a
19-
href={announcementLink}
20-
className="hidden md:inline hover:underline hover:text-night">
21-
{description}
22-
</a>
23-
</>
17+
isExternalLink ? (
18+
<>
19+
<a
20+
href={announcementLink}
21+
target="_blank"
22+
rel="noopener noreferrer"
23+
className="md:hidden hover:underline hover:text-night">
24+
{shortDescription}
25+
</a>
26+
<a
27+
href={announcementLink}
28+
target="_blank"
29+
rel="noopener noreferrer"
30+
className="hidden md:inline hover:underline hover:text-night">
31+
{description}
32+
</a>
33+
</>
34+
) : (
35+
<>
36+
<Link
37+
to={announcementLink}
38+
className="md:hidden hover:underline hover:text-night">
39+
{shortDescription}
40+
</Link>
41+
<Link
42+
to={announcementLink}
43+
className="hidden md:inline hover:underline hover:text-night">
44+
{description}
45+
</Link>
46+
</>
47+
)
2448
) : (
2549
<>
2650
<span className="md:hidden">{shortDescription}</span>

0 commit comments

Comments
 (0)