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 (
Failed to load gist.{" "} Try opening it manually?
); } const script = await scriptResponse.text(); // https://github.com/tleunen/react-gist/blob/master/src/index.js#L29 const iframeHtml = `