/
iframe.js
365 lines (346 loc) · 9.05 KB
/
iframe.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
import {
ImagePlaceholder,
Subhead,
Box,
Flex,
Container,
Text,
Link,
MultiCodeEditor
} from 'components/elements'
import { Grid, SubHeadline, Layout } from 'components/patterns'
import React, { useState, useEffect } from 'react'
import styled from 'styled-components'
import mql from '@microlink/mql'
import { layout } from 'theme'
const TITLE = 'Embed makes easy'
const DEMO_URL = 'https://www.youtube.com/watch?v=Gu8X7vM3Avw'
const SCALE_FACTOR = 0.85
const IFRAME_WIDTH = 560 * SCALE_FACTOR
const IFRAME_HEIGHT = 315 * SCALE_FACTOR
const IframeWrapper = styled(Box)`
iframe {
width: ${IFRAME_WIDTH}px;
height: ${IFRAME_HEIGHT}px;
max-width: 100%;
max-height: calc((100vw - 40px) / (16 / 9));
}
`
const react = () => `
import React, { useState, useEffect } from 'react'
import mql from '@microlink/mql'
export default ({ url }) => {
const [iframe, setIframe] = useState(null)
useEffect(() => {
async function fetchData () {
const { data } = await mql(url, {
meta: false,
iframe: true
})
setIframe(data.iframe)
}
fetchData()
}, [])
return(
iframe
? <div dangerouslySetInnerHTML={{ __html: iframe }}/>
: 'Loading...'
)
}
`
const javascript = () => `
const mql = require('@microlink/mql')
const { data } = await mql('${DEMO_URL}', {
meta: false,
iframe: true
})
return data
`
const shell = () =>
`$ curl -sL https://api.microlink.io?url=${DEMO_URL}&meta=false&iframe`
const languages = { Shell: shell, 'Node.js': javascript, React: react }
const Embed = ({ title, description, url }) => {
const [iframe, setIframe] = useState(null)
useEffect(() => {
async function fetchData () {
const { data } = await mql(url, {
meta: false,
iframe: true
})
setIframe(data.iframe)
}
fetchData()
}, [])
if (!iframe) {
return (
<Box mb={4} px={[3, 4]}>
<ImagePlaceholder width={IFRAME_WIDTH} height={IFRAME_HEIGHT} />
</Box>
)
}
return (
<Box as='section' mb={4} px={[3, 4]}>
<Box as='header' ml={2} mb={2}>
<Subhead as='span' fontSize={[1, 2]}>
{title}
</Subhead>
<Text as='span' ml={2} color='gray' fontSize={[0, 1]}>
{description}
</Text>
</Box>
<IframeWrapper dangerouslySetInnerHTML={{ __html: iframe }} />
</Box>
)
}
const links = [
{
title: 'YouTube',
description: 'video',
url: 'https://youtu.be/Gu8X7vM3Avw'
},
{
title: 'YouTube',
description: 'playlist',
url:
'https://www.youtube.com/watch?v=-TWztwbOpog&list=PL5aqr5w5fRe4nO30px44D5sBukIUw1UwX'
},
{ title: 'Vimeo', description: 'video', url: 'https://vimeo.com/135373919' },
{
title: 'Spotify',
description: 'song',
url:
'https://open.spotify.com/track/63W11KVHDOpSlh3XMQ7qMg?si=Yd-hIkD9TtSUeFeR0jzKsA'
},
{
title: 'Spotify',
description: 'playlist',
url:
'https://open.spotify.com/playlist/1xY6msLHX1W34EzB0UkkbU?si=cFF7LjzgQxWz5ni6TCN_jA'
},
{
title: 'Instagram',
description: 'photo',
url: 'https://www.instagram.com/farid_rueda/p/Bx-0nVPCe2c/'
},
{
title: 'Instagram',
description: 'video',
url: 'https://www.instagram.com/p/BeV6tOhFUor/'
},
{
title: 'Twitter',
description: 'video',
url: 'https://twitter.com/tribandtweets/status/1133308311917481984'
},
{
title: 'Twitter',
description: 'status',
url: 'https://twitter.com/NetflixDE/status/1133310428476530688'
},
{
title: 'Twitter',
description: 'photo',
url: 'https://twitter.com/officialmcafee/status/1133280322039291905'
},
{
title: 'TED',
description: 'video',
url:
'https://www.ted.com/talks/monique_w_morris_why_black_girls_are_targeted_for_punishment_at_school_and_how_to_change_that?utm_campaign=tedspread&utm_medium=referral&utm_source=tedcomshare'
},
{
title: 'Facebook',
description: 'video',
url: 'https://www.facebook.com/watch/?v=364684367488603'
},
{
title: 'Facebook',
description: 'photo',
url:
'https://www.facebook.com/alternate.de/photos/a.391014166661/10156375231596662/?type=3&theater'
},
{
title: 'SoundCloud',
description: 'song',
url: 'https://soundcloud.com/beautybrainsp/beauty-brain-swag-bandicoot'
},
{
title: 'Twitch',
description: 'clip',
url:
'https://www.twitch.tv/lvpes/clip/TsundereJoyousPheasantMikeHogu?filter=all&sort=time'
},
{
title: 'CodePen',
description: 'snippet',
url: 'https://codepen.io/hbagency/pen/eKyObz'
},
{
title: 'CodeSandbox',
description: 'sandbox',
url: 'https://codesandbox.io/s/gracious-blackburn-n5w839zm4m'
},
{
title: 'Dailymotion',
description: 'video',
url: 'https://www.dailymotion.com/video/x7ntzjb?playlist=x5v2j4'
},
{
title: 'DeviantArt',
description: 'publication',
url: 'https://www.deviantart.com/glitchyxenon/art/Daft-Punk-f2u-663024393'
},
{
title: 'Flickr',
description: 'photo',
url:
'https://www.flickr.com/photos/fotodudenz/184588922/in/faves-49014237@N00/'
},
{
title: 'gfycat',
description: 'gif',
url: 'https://gfycat.com/timelyhealthyarmadillo'
},
{
title: 'GIPHY',
description: 'gif',
url:
'https://giphy.com/gifs/sonicmovie-sonic-the-hedgehog-VFMu7SKAsaPFEkab2f'
},
{
title: 'Gyazo',
description: 'gif',
url: 'https://gyazo.com/41a363bc94d18a49eb762b719075530d'
},
{
title: 'Stremeable',
description: 'gif',
url: 'https://streamable.com/46ont'
},
{
title: 'iFixit',
description: 'publication',
url:
'https://www.ifixit.com/Teardown/Microsoft+Surface+Pro+X+Teardown/127703'
},
{
title: 'IFTTT',
description: 'recipe',
url:
'https://ifttt.com/applets/UHcg5jkZ-quickly-email-yourself-a-note?term=email'
},
{
title: 'Kickstarter',
description: 'project',
url:
'https://www.kickstarter.com/projects/raine-scooters/the-raine-one-electric-scooter?ref=section-homepage-projectcollection-10-staff-picks-newest'
},
{
title: 'Kit',
description: 'publication',
url: 'https://kit.com/MKBHD/my-setup'
},
{
title: 'Meetup',
description: 'publication',
url: 'https://www.meetup.com/amurbit-Murcia-Bitcoin-blockchain/'
},
{
title: 'Mixcloud',
description: 'song',
url:
'https://www.mixcloud.com/quietmusic/quietmusic-november-10-hour-3-excerpt/'
},
{
title: 'Overflow',
description: 'publication',
url: 'https://overflow.io/s/9ST7SX/'
},
{
title: 'Reddit',
description: 'publication',
url:
'https://www.reddit.com/r/outrun/comments/dvan65/an_outrun_style_christmas_sweater_design_i_made/'
},
{
title: 'SlideShare',
description: 'slides',
url:
'https://www.slideshare.net/fusion2011/github-githubgithub?qid=7d621cf6-9573-40ea-8d29-e4332db545fd&v=&b=&from_search=1'
},
{
title: 'Speaker Deck',
description: 'slides',
url: 'https://speakerdeck.com/holman/how-github-no-longer-works'
},
{
title: 'NY Times',
description: 'news',
url:
'https://www.nytimes.com/interactive/2019/11/12/arts/television/disney-plus-shows-movies.html?action=click&module=Editors%20Picks&pgtype=Homepage'
}
]
export default () => {
return (
<Layout title={TITLE}>
<Container py={[4, 5]} px={4} maxWidth={layout.large}>
<SubHeadline title={TITLE} caption='Turn links into embeddable media' />
<Subhead
children='How it works'
px={4}
pt={4}
pb={3}
textAlign='left'
fontSize={3}
/>
<Text px={4} ml={3}>
Given an URL (Twitter, Instagram, Facebook, YouTube, Spotify, etc),
Microlink API retrieves you the snippet code necessary for embedding
the representation of the URL in your site.
</Text>
<Text pt={3} px={4} ml={3}>
Any site that follows{' '}
<Link href='https://oembed.com' icon>
oembed
</Link>{' '}
specification is supported. See the full list of compatible{' '}
<Link href='https://oembed.com/providers.json' icon>
providers
</Link>{' '}
.
</Text>
<Subhead
children='How to use'
px={4}
pt={4}
pb={3}
textAlign='left'
fontSize={3}
/>
<Text px={4} ml={3}>
Just attach `iframe` query parameter when you interact with{' '}
<Link href='/docs/api/getting-started/overview'>Microlink API</Link>
</Text>
<Box pt={3} px={6}>
<MultiCodeEditor languages={languages} />
</Box>
<Subhead
children='Demo'
px={4}
pt={4}
pb={3}
textAlign='left'
fontSize={3}
/>
<Flex px={3} alignItems='center' justifyContent='center'>
<Grid
children={links}
childComponent={Embed}
itemsPerRow={1}
justifyContent='center'
/>
</Flex>
</Container>
</Layout>
)
}