Skip to content

Commit 3fd3b71

Browse files
committed
fix: server side rendering
1 parent 95e23e8 commit 3fd3b71

File tree

5 files changed

+58
-20
lines changed

5 files changed

+58
-20
lines changed

gatsby-config.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* @file Gatsby config
3+
*/
4+
15
require('dotenv').config()
26
const path = require('path')
37

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"root": true
5454
},
5555
"dependencies": {
56+
"@loadable/component": "^5.14.1",
5657
"gatsby": "^2.31.1",
5758
"gatsby-image": "^2.10.0",
5859
"gatsby-plugin-google-analytics": "^2.10.0",
@@ -77,6 +78,7 @@
7778
"devDependencies": {
7879
"@ntnyq/eslint-config-prettier-typescript-react": "^0.1.12",
7980
"@ntnyq/prettier-config": "^0.2.0",
81+
"@types/loadable__component": "^5.13.1",
8082
"@types/react": "^17.0.0",
8183
"@types/react-dom": "^17.0.0",
8284
"@types/react-helmet": "^6.0.0",

src/components/AudioPlayer/index.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
import loadable from '@loadable/component'
3+
import 'react-jinke-music-player/assets/index.css'
4+
import type { ReactJkMusicPlayerProps } from 'react-jinke-music-player'
5+
6+
const ReactJkMusicPlayer = loadable(() => import('react-jinke-music-player'))
7+
8+
interface Props {
9+
options: ReactJkMusicPlayerProps
10+
}
11+
12+
const VideoPlayer: React.FC<Props> = ({ children, options }) => (
13+
<ReactJkMusicPlayer {...options}>{children}</ReactJkMusicPlayer>
14+
)
15+
16+
export default VideoPlayer

src/components/Hero/index.tsx

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react'
22
import styled from 'styled-components'
33
import { useStaticQuery, graphql } from 'gatsby'
4-
import ReactJkMusicPlayer, {
4+
import VideoPlayer from '../AudioPlayer'
5+
import type {
6+
ReactJkMusicPlayerLocale,
57
ReactJkMusicPlayerAudioListProps,
68
} from 'react-jinke-music-player'
7-
import 'react-jinke-music-player/assets/index.css'
89
import { DataJson } from '../../../generated-types/gatsby-graphql'
910
import {
1011
Container as ContainerComponent,
@@ -51,6 +52,20 @@ const Hero: React.FC = () => {
5152
const {
5253
dataJson: { sns, audioLists },
5354
} = useStaticQuery<{ dataJson: DataJson }>(query)
55+
const options = {
56+
locale: 'zh_CN' as ReactJkMusicPlayerLocale,
57+
defaultVolume: 0.5,
58+
defaultPosition: { left: 20, bottom: 20 },
59+
drag: false,
60+
glassBg: true,
61+
autoPlay: false,
62+
toggleMode: true,
63+
showLyric: false,
64+
showDestroy: false,
65+
showDownload: false,
66+
showThemeSwitch: false,
67+
audioLists: audioLists as ReactJkMusicPlayerAudioListProps[],
68+
}
5469

5570
return (
5671
<Container>
@@ -62,22 +77,7 @@ const Hero: React.FC = () => {
6277
</Button>
6378
))}
6479
</Buttons>
65-
{audioLists && (
66-
<ReactJkMusicPlayer
67-
locale='zh_CN'
68-
defaultVolume={0.5}
69-
defaultPosition={{ left: 20, bottom: 20 }}
70-
drag={false}
71-
glassBg={true}
72-
autoPlay={false}
73-
toggleMode={true}
74-
showLyric={false}
75-
showDestroy={false}
76-
showDownload={false}
77-
showThemeSwitch={false}
78-
audioLists={audioLists as ReactJkMusicPlayerAudioListProps[]}
79-
/>
80-
)}
80+
{audioLists && <VideoPlayer options={options} />}
8181
</Container>
8282
)
8383
}

yarn.lock

+18-2
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@
932932
core-js-pure "^3.0.0"
933933
regenerator-runtime "^0.13.4"
934934

935-
"@babel/runtime@^7.0.0", "@babel/runtime@^7.10.0", "@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.11.1", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.3.4", "@babel/runtime@^7.7.2", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
935+
"@babel/runtime@^7.0.0", "@babel/runtime@^7.10.0", "@babel/runtime@^7.10.1", "@babel/runtime@^7.10.2", "@babel/runtime@^7.11.1", "@babel/runtime@^7.11.2", "@babel/runtime@^7.12.5", "@babel/runtime@^7.3.4", "@babel/runtime@^7.7.2", "@babel/runtime@^7.7.7", "@babel/runtime@^7.8.4", "@babel/runtime@^7.9.2":
936936
version "7.12.5"
937937
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.12.5.tgz#410e7e487441e1b360c29be715d870d9b985882e"
938938
integrity sha512-plcc+hbExy3McchJCEQG3knOsuh3HH+Prx1P6cLIkET/0dLuQDEnrT+s27Axgc9bqfsmNUNHfscgMUdBpC9xfg==
@@ -1696,6 +1696,15 @@
16961696
"@babel/runtime" "^7.7.2"
16971697
regenerator-runtime "^0.13.3"
16981698

1699+
"@loadable/component@^5.14.1":
1700+
version "5.14.1"
1701+
resolved "https://registry.yarnpkg.com/@loadable/component/-/component-5.14.1.tgz#cacd807162430bb85ae085945318027a600adc85"
1702+
integrity sha512-UQBZfZrp1FLTf8RNhljXNHFNY4QhAA1L2+GOEeABBFre9TD0aFyQh3Sai5QxcOfy+FTbjIfti5iHaNRR7yUzEQ==
1703+
dependencies:
1704+
"@babel/runtime" "^7.7.7"
1705+
hoist-non-react-statics "^3.3.1"
1706+
react-is "^16.12.0"
1707+
16991708
"@mdx-js/util@^2.0.0-next.8":
17001709
version "2.0.0-next.8"
17011710
resolved "https://registry.yarnpkg.com/@mdx-js/util/-/util-2.0.0-next.8.tgz#66ecc27b78e07a3ea2eb1a8fc5a99dfa0ba96690"
@@ -2022,6 +2031,13 @@
20222031
dependencies:
20232032
"@types/node" "*"
20242033

2034+
"@types/loadable__component@^5.13.1":
2035+
version "5.13.1"
2036+
resolved "https://registry.yarnpkg.com/@types/loadable__component/-/loadable__component-5.13.1.tgz#97c24081676a194b29722ff6e3c24a3676984f2e"
2037+
integrity sha512-Zb/Qkw3BnlRoFkL6FJwDvhFhOfeotXRCWd7dHdjVLusHZ3dZjKNi3ERngYBt3tffk2NF4roGVKA/oZMA1KdbCg==
2038+
dependencies:
2039+
"@types/react" "*"
2040+
20252041
"@types/lodash@^4.14.92":
20262042
version "4.14.166"
20272043
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.166.tgz#07e7f2699a149219dbc3c35574f126ec8737688f"
@@ -7828,7 +7844,7 @@ hmac-drbg@^1.0.0:
78287844
minimalistic-assert "^1.0.0"
78297845
minimalistic-crypto-utils "^1.0.1"
78307846

7831-
hoist-non-react-statics@^3.0.0, hoist-non-react-statics@^3.3.0:
7847+
hoist-non-react-statics@^3.0.0, hoist-non-react-statics@^3.3.0, hoist-non-react-statics@^3.3.1:
78327848
version "3.3.2"
78337849
resolved "https://registry.yarnpkg.com/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz#ece0acaf71d62c2969c2ec59feff42a4b1a85b45"
78347850
integrity sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==

0 commit comments

Comments
 (0)