Skip to content

Commit 48b607b

Browse files
authored
Merge pull request #56 from zoobestik/gif-player
fix; build time for gif-player
2 parents 163da1d + 9bcf416 commit 48b607b

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/components/Markdown/index.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import {createContext, ReactNode, useContext} from "react";
1+
import {createContext, lazy, ReactNode, Suspense, useContext} from "react";
22
import cn from "classnames";
33
import {MDXProvider} from "@mdx-js/react";
44
import {LinkIcon} from "@rescui/icons";
5-
import GifPlayer from "react-gif-player";
65
import {useTextStyles} from "@jetbrains/kotlin-web-site-ui/out/components/typography";
76

8-
import {useSiteMeta} from "../../utlis/hooks";
7+
import {useSiteMeta, useSiteURL} from "../../utlis/hooks";
98
import {Link} from "../Link";
109

1110
import * as CUSTOM_MARKDOWN_TAGS from "./CustomTags";
@@ -14,6 +13,8 @@ import "./gif-player.css";
1413
import * as styles from "./modern.module.css";
1514
import {cls} from "../../utlis";
1615

16+
const GifPlayer = lazy(() => import("react-gif-player"));
17+
1718
const OLAlpha = [ 'upper', 'lower' ];
1819
export const OLContext = createContext<number | null>(null);
1920

@@ -101,11 +102,15 @@ const MODERN_SHORT_CODES = {
101102
blockquote: props => <blockquote {...cls(props, styles.quote)}/>,
102103
pre: props => <div><pre {...cls(props, 'ktl-text-2', styles.codeBlock)}/></div>,
103104
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;
109114
},
110115

111116
// strong: props => <strong {...cls(props, 'ktl-')}/>,

0 commit comments

Comments
 (0)