Skip to content

Commit aac0a6f

Browse files
authored
Added case to enable videos in articles (#208)
1 parent e4d3deb commit aac0a6f

File tree

4 files changed

+69
-5
lines changed

4 files changed

+69
-5
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
"react-dom": "16.8.6",
7979
"react-emotion": "^9.2.12",
8080
"react-helmet": "^5.2.0",
81+
"react-player": "2.14.1",
8182
"react-plyr": "^2.1.1",
8283
"react-string-replace": "0.4.4",
8384
"slugify": "^1.3.3",

src/components/Article/index.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as React from 'react'
22
import { css } from 'react-emotion'
33
import Image, { ImageProps } from '../Image'
4+
import Video, { VideoProps } from '../Video'
45

56
enum ContentType {
67
Text = 'text',
78
Image = 'image',
9+
Video = 'video',
810
Line = 'line',
911
}
1012

@@ -52,6 +54,9 @@ export default class Article extends React.Component<ArticleProps> {
5254
case ContentType.Image:
5355
const image = JSON.parse(content.value) as ImageProps
5456
return <Image key={i} {...image} />
57+
case ContentType.Video:
58+
const video = JSON.parse(content.value) as VideoProps
59+
return <Video key={i} {...video} />
5560
case ContentType.Line:
5661
return <hr />
5762
default:

src/components/Video/index.tsx

+32-5
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,42 @@
22
/// <reference path="index.d.ts"/>
33

44
import * as React from 'react'
5-
import Plyr from 'react-plyr'
6-
// tslint:disable-next-line
7-
import 'plyr/dist/plyr.css'
5+
import { css } from 'react-emotion'
6+
import ReactPlayer from 'react-player'
87

98
export interface VideoProps {
109
/** The id of the YouTube video. */
11-
videoId: string
10+
url: string
11+
caption: string
12+
credit: string
13+
alt: string
14+
/** Custom css for the image component */
15+
style?: string
1216
}
1317

1418
export default function Video(props: VideoProps) {
15-
return <Plyr type="youtube" {...props} />
19+
return (
20+
<figure className={props.style}>
21+
<div
22+
className={css`
23+
position: relative;
24+
padding-top: 56.25%; /* Player ratio: 100 / (1280 / 720) */
25+
`}
26+
>
27+
<ReactPlayer
28+
className={css`
29+
position: absolute;
30+
top: 0;
31+
left: 0;
32+
`}
33+
url={props.url}
34+
width="100%"
35+
height="100%"
36+
/>
37+
</div>
38+
<figcaption>
39+
{props.caption} ({props.credit})
40+
</figcaption>
41+
</figure>
42+
)
1643
}

yarn.lock

+31
Original file line numberDiff line numberDiff line change
@@ -5502,6 +5502,11 @@ deepmerge@^2.1.1:
55025502
version "2.2.1"
55035503
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170"
55045504

5505+
deepmerge@^4.0.0:
5506+
version "4.3.1"
5507+
resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-4.3.1.tgz#44b5f2147cd3b00d4b56137685966f26fd25dd4a"
5508+
integrity sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==
5509+
55055510
default-compare@^1.0.0:
55065511
version "1.0.0"
55075512
resolved "https://registry.yarnpkg.com/default-compare/-/default-compare-1.0.0.tgz#cb61131844ad84d84788fb68fd01681ca7781a2f"
@@ -10477,6 +10482,11 @@ load-json-file@^4.0.0:
1047710482
pify "^3.0.0"
1047810483
strip-bom "^3.0.0"
1047910484

10485+
load-script@^1.0.0:
10486+
version "1.0.0"
10487+
resolved "https://registry.yarnpkg.com/load-script/-/load-script-1.0.0.tgz#0491939e0bee5643ee494a7e3da3d2bac70c6ca4"
10488+
integrity sha512-kPEjMFtZvwL9TaZo0uZ2ml+Ye9HUMmPwbYRJ324qF9tqMejwykJ5ggTyvzmrbBeapCAbk98BSbTeovHEEP1uCA==
10489+
1048010490
loader-fs-cache@^1.0.0:
1048110491
version "1.0.2"
1048210492
resolved "https://registry.yarnpkg.com/loader-fs-cache/-/loader-fs-cache-1.0.2.tgz#54cedf6b727e1779fd8f01205f05f6e88706f086"
@@ -10997,6 +11007,11 @@ memoize-one@^5.0.0:
1099711007
version "5.0.4"
1099811008
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.0.4.tgz#005928aced5c43d890a4dfab18ca908b0ec92cbc"
1099911009

11010+
memoize-one@^5.1.1:
11011+
version "5.2.1"
11012+
resolved "https://registry.yarnpkg.com/memoize-one/-/memoize-one-5.2.1.tgz#8337aa3c4335581839ec01c3d594090cebe8f00e"
11013+
integrity sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==
11014+
1100011015
memory-fs@^0.4.0, memory-fs@^0.4.1, memory-fs@~0.4.1:
1100111016
version "0.4.1"
1100211017
resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552"
@@ -13483,6 +13498,11 @@ react-fast-compare@^2.0.2:
1348313498
version "2.0.4"
1348413499
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-2.0.4.tgz#e84b4d455b0fec113e0402c329352715196f81f9"
1348513500

13501+
react-fast-compare@^3.0.1:
13502+
version "3.2.2"
13503+
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"
13504+
integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==
13505+
1348613506
react-feather@^1.1.6:
1348713507
version "1.1.6"
1348813508
resolved "https://registry.yarnpkg.com/react-feather/-/react-feather-1.1.6.tgz#2a547e3d5cd5e383d3da0128d593cbdb3c1b32f7"
@@ -13560,6 +13580,17 @@ react-perfect-scrollbar@^1.5.0:
1356013580
perfect-scrollbar "^1.4.0"
1356113581
prop-types "^15.6.1"
1356213582

13583+
react-player@2.14.1:
13584+
version "2.14.1"
13585+
resolved "https://registry.yarnpkg.com/react-player/-/react-player-2.14.1.tgz#fc434c0e1e6161e76f5d5970721596c4acec52b1"
13586+
integrity sha512-jILj7F9o+6NHzrJ1GqZIxfJgskvGmKeJ05FNhPvgiCpvMZFmFneKEkukywHcULDO2lqITm+zcEkLSq42mX0FbA==
13587+
dependencies:
13588+
deepmerge "^4.0.0"
13589+
load-script "^1.0.0"
13590+
memoize-one "^5.1.1"
13591+
prop-types "^15.7.2"
13592+
react-fast-compare "^3.0.1"
13593+
1356313594
react-plyr@^2.1.1:
1356413595
version "2.2.0"
1356513596
resolved "https://registry.yarnpkg.com/react-plyr/-/react-plyr-2.2.0.tgz#94b0b2f815411d1af65de9694059eaab8a726c75"

0 commit comments

Comments
 (0)