forked from InvolutionHell/involutionhell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmdx-components.tsx
More file actions
59 lines (54 loc) · 1.55 KB
/
mdx-components.tsx
File metadata and controls
59 lines (54 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// import Image from "next/image";
// import type { ImageProps } from "next/image";
import defaultMdxComponents from "fumadocs-ui/mdx";
import type { MDXComponents } from "mdx/types";
// import type { ComponentPropsWithoutRef } from "react";
// type MdxImageProps = ComponentPropsWithoutRef<"img"> & {
// src?: ImageProps["src"];
// width?: number | string;
// height?: number | string;
// };
// function MdxImage({ src, alt = "", width, height, ...rest }: MdxImageProps) {
// if (!src) {
// return (
// <img
// src={src as string}
// alt={alt}
// width={width}
// height={height}
// {...rest}
// />
// );
// }
// const numericWidth = typeof width === "string" ? Number(width) : width;
// const numericHeight = typeof height === "string" ? Number(height) : height;
// if (!Number.isFinite(numericWidth) || !Number.isFinite(numericHeight)) {
// // fallback: 当 width/height 不是可解析数值时,直接使用原生 <img>
// return <img src={src ?? ""} alt={alt ?? ""} {...rest} />;
// }
// return (
// <Image
// src={src ?? ""}
// alt={alt ?? ""}
// width={numericWidth}
// height={numericHeight}
// {...rest}
// />
// );
// return (
// <img
// src={src as string}
// alt={alt}
// width={width}
// height={height}
// {...rest}
// />
// );
// }
export function getMDXComponents(components?: MDXComponents): MDXComponents {
return {
...defaultMdxComponents,
// img: MdxImage,
...components,
};
}