1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-06-05 19:15:30 -04:00
Files
jarv.is/mdx-components.tsx
T
jake 5a1636baa3 refactor: migrate from Biome to oxlint/oxfmt, remove contact form
- Replace Biome with oxlint + oxfmt (OXC toolchain) for linting and formatting
- Add .oxlintrc.json and .oxfmtrc.json configuration files
- Update VS Code settings and devcontainer to use oxc-vscode extension
- Remove contact form, Resend email integration, and related server action/schema
- Remove unused UI components (accordion, alert, card, tabs, toggle, etc.)
2026-04-05 19:45:18 -04:00

66 lines
2.1 KiB
TypeScript

import type { MDXComponents } from "mdx/types";
import Image from "next/image";
import Link from "next/link";
import { CodeBlock } from "@/components/code-block";
import { ImageDiff } from "@/components/image-diff";
import { CodePen } from "@/components/third-party/codepen";
import { Gist } from "@/components/third-party/gist";
import { Tweet } from "@/components/third-party/tweet";
import { YouTube } from "@/components/third-party/youtube";
import { Video } from "@/components/video";
import { cn } from "@/lib/utils";
export const useMDXComponents = (components: MDXComponents): MDXComponents => {
return {
...components,
a: ({ href, rel, target, children, ...rest }: React.ComponentProps<typeof Link>) => {
const isExternal = typeof href === "string" && !["/", "#"].includes(href[0]);
if (isExternal) {
return (
<a href={href} rel={rel || "noopener noreferrer"} target={target || "_blank"} {...rest}>
{children}
</a>
);
}
return (
<Link href={href} rel={rel} target={target} {...rest}>
{children}
</Link>
);
},
pre: CodeBlock,
img: ({ src, alt, className, ...rest }: React.ComponentProps<typeof Image>) => {
const imageWidth =
typeof src === "object" && "width" in src && src.width > 896 ? 896 : undefined;
const imageHeight =
imageWidth && typeof src === "object" && "width" in src && "height" in src
? Math.round((src.height / src.width) * imageWidth)
: undefined;
return (
<Image
src={src}
alt={alt}
width={imageWidth}
height={imageHeight}
className={cn(
"mx-auto my-8 block h-auto max-w-full rounded-sm",
"[&+em]:text-muted-foreground [&+em]:-mt-4 [&+em]:block [&+em]:text-center [&+em]:text-[0.875em] [&+em]:leading-normal [&+em]:font-medium [&+em]:not-italic",
className,
)}
{...rest}
/>
);
},
// React components and embeds:
Video,
ImageDiff,
Tweet,
YouTube,
Gist,
CodePen,
};
};