mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-06-19 10:55:31 -04:00
5a1636baa3
- 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.)
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { cacheLife, cacheTag } from "next/cache";
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
const Gist = async ({
|
|
id,
|
|
file,
|
|
title,
|
|
className,
|
|
...rest
|
|
}: {
|
|
id: string;
|
|
file?: string;
|
|
title?: string;
|
|
} & React.ComponentProps<"iframe">) => {
|
|
"use cache";
|
|
cacheLife("max");
|
|
cacheTag("gist", `gist-${id}${file ? `-${file}` : ""}`);
|
|
|
|
const iframeId = `gist-${id}${file ? `-${file}` : ""}`;
|
|
|
|
const iframeTitle = title ?? `GitHub Gist ${id}${file ? ` - ${file}` : ""}`;
|
|
|
|
const scriptUrl = `https://gist.github.com/${id}.js${file ? `?file=${file}` : ""}`;
|
|
const scriptResponse = await fetch(scriptUrl);
|
|
|
|
if (!scriptResponse.ok) {
|
|
console.warn(`[gist] failed to fetch js:`, scriptResponse.statusText);
|
|
|
|
return (
|
|
<p className="text-center">
|
|
Failed to load gist.{" "}
|
|
<a
|
|
href={`https://gist.github.com/${id}${file ? `?file=${file}` : ""}`}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
>
|
|
Try opening it manually?
|
|
</a>
|
|
</p>
|
|
);
|
|
}
|
|
|
|
const script = await scriptResponse.text();
|
|
|
|
// https://github.com/tleunen/react-gist/blob/master/src/index.js#L29
|
|
const iframeHtml = `<html><head><base target="_parent"></head><body onload="parent.document.getElementById('${iframeId}').style.height=document.body.scrollHeight + 'px'" style="margin:0"><script>${script}</script></body></html>`;
|
|
|
|
return (
|
|
<iframe
|
|
width="100%"
|
|
scrolling="no"
|
|
id={iframeId}
|
|
srcDoc={iframeHtml}
|
|
title={iframeTitle}
|
|
sandbox="allow-scripts"
|
|
className={cn("overflow-hidden border-none", className)}
|
|
{...rest}
|
|
suppressHydrationWarning
|
|
/>
|
|
);
|
|
};
|
|
|
|
export { Gist };
|