-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheleventy.config.videos.js
31 lines (29 loc) · 994 Bytes
/
eleventy.config.videos.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
function videoShortcode(host, source, credit, autoplay) {
let url = undefined
switch (host) {
case 'youtube':
url = `https://www.youtube.com/embed/${source}?autoplay=${
autoplay ? '1' : '0'
}&loop=0&controls=0&modestbranding=1`
break
case 'vimeo':
url = `https://player.vimeo.com/video/${source}?autoplay=${
autoplay ? '1' : '0'
}&loop=0&title=0&byline=0&portrait=0`
break
default:
break
}
return `<div class="my-4 lg:my-6 bg-stone-200">
<div class="relative w-full h-0 pb-16/9 overflow-hidden"><iframe src=${url} allow="autoplay; encrypted-media" frameBorder="0" class="absolute top-0 left-0 w-full h-full border-0"></iframe></div>
${
typeof credit === 'string'
? `<figcaption class="font-serif italic text-sm opacity-50 text-center mt-1">${credit}</figcaption>`
: ''
}
</div>
`
}
module.exports = eleventyConfig => {
eleventyConfig.addShortcode('video', videoShortcode)
}