@theguild/components
Version:
52 lines (51 loc) • 1.78 kB
JavaScript
import { jsx, jsxs } from "react/jsx-runtime";
import fs from "fs/promises";
import path from "path";
import { addBasePath } from "next/dist/client/add-base-path";
import clsx from "clsx";
import { useMDXComponents as getDocsMDXComponents } from "nextra-theme-docs";
const docsComponents = getDocsMDXComponents({
async source({ src, type, ...props }) {
if (!src) {
throw new Error("Must provide `src` prop");
}
if (src.startsWith("/")) {
const filePath = path.join(process.cwd(), "public", src);
try {
await fs.access(filePath);
} catch (error) {
const relativePath = path.relative(process.cwd(), filePath);
if (error.code === "ENOENT") {
throw new Error(`File doesn't exist: ${relativePath}`);
}
throw new Error(`Error checking file: ${relativePath}`);
}
}
let ext = path.extname(src).slice(1);
if (ext === "mov") {
ext = "quicktime";
}
return /* @__PURE__ */ jsx("source", { ...props, src: addBasePath(src), type: type || `video/${ext}` });
},
video: ({ className, children, ...props }) => /* @__PURE__ */ jsxs("video", { className: clsx("mt-6 w-full", className), autoPlay: true, loop: true, muted: true, ...props, children: [
children,
"Your browser does not support HTML video."
] }),
iframe: ({ className, ...props }) => /* @__PURE__ */ jsx(
"iframe",
{
className: clsx("mt-6 aspect-video w-full", className),
title: "YouTube Video Player",
allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
allowFullScreen: true,
...props
}
)
});
const useMDXComponents = (components) => ({
...docsComponents,
...components
});
export {
useMDXComponents
};