Skip to content

Commit

Permalink
bugfix: make external links open in new tabs
Browse files Browse the repository at this point in the history
introduce an external link component to facilitate them always opening in new tabs
introduce rel=noreferrer to prevent javascript hijacking by target tabs

Closes EddieHubCommunity#107
  • Loading branch information
Idrinth committed Jun 30, 2024
1 parent 1beffb4 commit 6b42e81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/components/ExternalLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Link from "next/link";

export default function ExternalLink({ href, children, ...rest }) {
return <Link target={"_blank"} rel={"noreferrer"} href={href} {...rest}>{ children }</Link>;
}
4 changes: 2 additions & 2 deletions src/components/Footer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import data from "@/config/app.json";
import Link from "next/link";
import ExternalLink from "@/components/ExternalLink";

export default function Footer() {
const githubUrl = "https://github.com/EddieHubCommunity/CreatorsRegistry";
Expand All @@ -11,7 +11,7 @@ export default function Footer() {
&copy; {new Date().getFullYear()} EddieHub All rights reserved | v
{data.version}
</div>
<Link href={githubUrl}>{githubUrl}</Link>
<ExternalLink href={githubUrl}>{githubUrl}</ExternalLink>
</div>
</footer>
);
Expand Down
6 changes: 3 additions & 3 deletions src/components/list/Item.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ChevronRightIcon } from "@heroicons/react/20/solid";
import Image from "next/image";
import Link from "next/link";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";

import Badge from "@/components/Badge";
import socialIcon from "@/config/socialIcon";
import ExternalLink from "@/components/ExternalLink";

export default function Item({ data }) {
return (
Expand All @@ -29,10 +29,10 @@ export default function Item({ data }) {
)}
<div className="min-w-0 flex-auto">
<p className="text-sm font-semibold leading-6 text-gray-900">
<Link href={data.url}>
<ExternalLink href={data.url}>
<span className="absolute inset-x-0 -top-px bottom-0" />
{data.urlText}
</Link>
</ExternalLink>
</p>
<p className="mt-1 flex text-xs leading-5 text-gray-500">
{data.description}
Expand Down

0 comments on commit 6b42e81

Please # to comment.