File tree 4 files changed +84
-0
lines changed
4 files changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ // @flow
2
+ import * as React from "react" ;
3
+ import Frame from "./components/Frame" ;
4
+
5
+ const URL_REGEX = new RegExp (
6
+ "^https?://drive.google.com/file/d/(.*)/(preview|view).?usp=sharing$"
7
+ ) ;
8
+
9
+ type Props = { |
10
+ attrs : { |
11
+ href : string ,
12
+ matches : string [ ] ,
13
+ | } ,
14
+ | } ;
15
+
16
+ export default class GoogleDrive extends React . Component < Props > {
17
+ static ENABLED = [ URL_REGEX ] ;
18
+
19
+ render ( ) {
20
+ return (
21
+ < Frame
22
+ src = { this . props . attrs . href . replace ( "/view" , "/preview" ) }
23
+ icon = {
24
+ < img
25
+ src = "/images/google-drive.png"
26
+ alt = "Google Drive Icon"
27
+ width = { 16 }
28
+ height = { 16 }
29
+ />
30
+ }
31
+ title = "Google Drive Embed"
32
+ canonicalUrl = { this . props . attrs . href }
33
+ border
34
+ />
35
+ ) ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ /* eslint-disable flowtype/require-valid-file-annotation */
2
+ import GoogleDrive from "./GoogleDrive" ;
3
+
4
+ describe ( "GoogleDrive" , ( ) => {
5
+ const match = GoogleDrive . ENABLED [ 0 ] ;
6
+ test ( "to be enabled on share link" , ( ) => {
7
+ expect (
8
+ "https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view?usp=sharing" . match (
9
+ match
10
+ )
11
+ ) . toBeTruthy ( ) ;
12
+ expect (
13
+ "https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/preview?usp=sharing" . match (
14
+ match
15
+ )
16
+ ) . toBeTruthy ( ) ;
17
+ } ) ;
18
+
19
+ test ( "to not be enabled elsewhere" , ( ) => {
20
+ expect (
21
+ "https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view" . match (
22
+ match
23
+ )
24
+ ) . toBe ( null ) ;
25
+ expect (
26
+ "https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/preview" . match (
27
+ match
28
+ )
29
+ ) . toBe ( null ) ;
30
+ expect (
31
+ "https://drive.google.com/file/d/1ohkOgmE8MiNx68u6ynBfYkgjeKu_x3ZK/view?usp=restricted" . match (
32
+ match
33
+ )
34
+ ) . toBeTruthy ( ) ;
35
+ expect ( "https://drive.google.com/file" . match ( match ) ) . toBe ( null ) ;
36
+ expect ( "https://drive.google.com" . match ( match ) ) . toBe ( null ) ;
37
+ expect ( "https://www.google.com" . match ( match ) ) . toBe ( null ) ;
38
+ } ) ;
39
+ } ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import Codepen from "./Codepen";
8
8
import Figma from "./Figma" ;
9
9
import Framer from "./Framer" ;
10
10
import Gist from "./Gist" ;
11
+ import GoogleDrive from "./GoogleDrive" ;
11
12
import GoogleDocs from "./GoogleDocs" ;
12
13
import GoogleSheets from "./GoogleSheets" ;
13
14
import GoogleSlides from "./GoogleSlides" ;
@@ -93,6 +94,13 @@ export default [
93
94
component : Gist ,
94
95
matcher : matcher ( Gist ) ,
95
96
} ,
97
+ {
98
+ title : "Google Drive" ,
99
+ keywords : "drive" ,
100
+ icon : ( ) => < Img src = "/images/google-drive.png" /> ,
101
+ component : GoogleDrive ,
102
+ matcher : matcher ( GoogleDrive ) ,
103
+ } ,
96
104
{
97
105
title : "Google Docs" ,
98
106
icon : ( ) => < Img src = "/images/google-docs.png" /> ,
You can’t perform that action at this time.
0 commit comments