Skip to content

Commit 7745a70

Browse files
authored
Open guide/challenge links in new tab (#324)
1 parent 8dbce5c commit 7745a70

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/nextjs/app/challenge/[challengeId]/page.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { createElement } from "react";
2+
import type { ComponentPropsWithoutRef } from "react";
13
import { notFound } from "next/navigation";
24
import { ChallengeHeader } from "./_components/ChallengeHeader";
35
import { ConnectAndRegisterBanner } from "./_components/ConnectAndRegisterBanner";
@@ -76,6 +78,10 @@ export default async function ChallengePage(props: { params: Promise<{ challenge
7678
<div className="prose dark:prose-invert max-w-fit break-words lg:max-w-[850px]">
7779
<MDXRemote
7880
source={restMdx}
81+
components={{
82+
a: (props: ComponentPropsWithoutRef<"a">) =>
83+
createElement("a", { ...props, target: "_blank", rel: "noopener" }),
84+
}}
7985
options={{
8086
mdxOptions: {
8187
rehypePlugins: [rehypeRaw],

packages/nextjs/services/guides.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ReactElement } from "react";
1+
import { ReactElement, createElement } from "react";
2+
import type { ComponentPropsWithoutRef } from "react";
23
import fs from "fs";
34
import { compileMDX } from "next-mdx-remote/rsc";
45
import path from "path";
@@ -33,7 +34,13 @@ export async function getGuideBySlug(slug: string): Promise<Guide | null> {
3334
const fileContents = fs.readFileSync(fullPath, "utf8");
3435
const { frontmatter, content } = await compileMDX<GuideMetadata>({
3536
source: fileContents,
36-
options: { parseFrontmatter: true },
37+
options: {
38+
parseFrontmatter: true,
39+
},
40+
components: {
41+
a: (props: ComponentPropsWithoutRef<"a">) =>
42+
createElement("a", { ...props, target: "_blank", rel: "noopener" }),
43+
},
3744
});
3845

3946
return {

0 commit comments

Comments
 (0)