Skip to content

Commit 8a5fc1a

Browse files
committed
feat: add optional href field to showcase and handle external links in ShowcaseCard
1 parent bc53290 commit 8a5fc1a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

apps/www/app/(marketing)/showcase/[...slug]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default async function PagePage({ params }: PageProps) {
8484
</h3>
8585
<ShowcaseCard
8686
title={doc.title ?? ""}
87-
href={page.url}
87+
href={doc.href ?? page.url}
8888
image={doc.image ?? ""}
8989
affiliation={doc.affiliation ?? ""}
9090
/>

apps/www/components/sections/showcase.tsx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import { ChevronRightIcon } from "@radix-ui/react-icons"
55
import { showcaseSource } from "@/lib/source"
66
import { Marquee } from "@/registry/magicui/marquee"
77

8+
function isExternalHref(href: string) {
9+
try {
10+
const url = new URL(href)
11+
return url.protocol === "http:" || url.protocol === "https:"
12+
} catch {
13+
return false
14+
}
15+
}
16+
817
export interface ShowcaseCardProps {
918
title: string
1019
image: string
@@ -17,9 +26,13 @@ export function ShowcaseCard({
1726
href,
1827
affiliation,
1928
}: ShowcaseCardProps) {
29+
const isExternal = isExternalHref(href)
2030
return (
2131
<Link
2232
href={href}
33+
prefetch={isExternal ? false : undefined}
34+
rel={isExternal ? "noopener noreferrer" : undefined}
35+
target={isExternal ? "_blank" : undefined}
2336
className="group relative flex cursor-pointer flex-col gap-2 overflow-hidden"
2437
>
2538
<Image

apps/www/source.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const showcase = defineDocs({
6363
schema: frontmatterSchema.extend({
6464
affiliation: z.string().optional(),
6565
featured: z.boolean().optional().default(false),
66+
href: z.string().url().optional(),
6667
image: z.string().optional(),
6768
}),
6869
},

0 commit comments

Comments
 (0)