1
- import { createContext , ReactNode , useContext } from "react" ;
1
+ import { createContext , lazy , ReactNode , Suspense , useContext } from "react" ;
2
2
import cn from "classnames" ;
3
3
import { MDXProvider } from "@mdx-js/react" ;
4
4
import { LinkIcon } from "@rescui/icons" ;
5
- import GifPlayer from "react-gif-player" ;
6
5
import { useTextStyles } from "@jetbrains/kotlin-web-site-ui/out/components/typography" ;
7
6
8
- import { useSiteMeta } from "../../utlis/hooks" ;
7
+ import { useSiteMeta , useSiteURL } from "../../utlis/hooks" ;
9
8
import { Link } from "../Link" ;
10
9
11
10
import * as CUSTOM_MARKDOWN_TAGS from "./CustomTags" ;
@@ -14,6 +13,8 @@ import "./gif-player.css";
14
13
import * as styles from "./modern.module.css" ;
15
14
import { cls } from "../../utlis" ;
16
15
16
+ const GifPlayer = lazy ( ( ) => import ( "react-gif-player" ) ) ;
17
+
17
18
const OLAlpha = [ 'upper' , 'lower' ] ;
18
19
export const OLContext = createContext < number | null > ( null ) ;
19
20
@@ -101,11 +102,15 @@ const MODERN_SHORT_CODES = {
101
102
blockquote : props => < blockquote { ...cls ( props , styles . quote ) } /> ,
102
103
pre : props => < div > < pre { ...cls ( props , 'ktl-text-2' , styles . codeBlock ) } /> </ div > ,
103
104
img : ( { src, ...props } ) => {
104
- const { pathname } = new URL ( src , window . location . href ) ;
105
-
106
- return pathname . endsWith ( '.gif' ) ?
107
- < GifPlayer { ...props } gif = { src } /> :
108
- < img src = { src } { ...props } />
105
+ const url = useSiteURL ( ) ;
106
+ const { pathname } = new URL ( src , url ) ;
107
+ const image = < img src = { src } { ...props } />
108
+
109
+ return typeof window !== 'undefined' && pathname . endsWith ( '.gif' ) ?
110
+ < Suspense fallback = { image } >
111
+ < GifPlayer { ...props } gif = { src } />
112
+ </ Suspense > :
113
+ image ;
109
114
} ,
110
115
111
116
// strong: props => <strong {...cls(props, 'ktl-')}/>,
0 commit comments