-
-
Notifications
You must be signed in to change notification settings - Fork 421
Expand file tree
/
Copy pathplyr.html
More file actions
85 lines (76 loc) 路 3.11 KB
/
Copy pathplyr.html
File metadata and controls
85 lines (76 loc) 路 3.11 KB
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
{{- /* Plyr */ -}}
{{- $plyrBase := "" -}}
{{- $useDefaultCdn := true -}}
{{- with site.Params.plyr.base -}}
{{- $plyrBase = . -}}
{{- $useDefaultCdn = false -}}
{{- end -}}
{{- $plyrJsAsset := "" -}}
{{- with site.Params.plyr.js -}}
{{- $plyrJsAsset = . -}}
{{- end -}}
{{- $plyrCssAsset := "" -}}
{{- with site.Params.plyr.css -}}
{{- $plyrCssAsset = . -}}
{{- end -}}
{{- /* If only js/css is set without base, use local asset loading */ -}}
{{- if and $useDefaultCdn (or (ne $plyrJsAsset "") (ne $plyrCssAsset "")) -}}
{{- $useDefaultCdn = false -}}
{{- end -}}
{{- /* Set default CDN base if needed */ -}}
{{- if $useDefaultCdn -}}
{{- $plyrBase = "https://cdn.jsdelivr.net/npm/plyr@latest/dist" -}}
{{- end -}}
{{- $isRemoteBase := or (strings.HasPrefix $plyrBase "http://") (strings.HasPrefix $plyrBase "https://") -}}
{{- $minSuffix := cond hugo.IsProduction ".min" "" -}}
{{- /* CSS retrieval */ -}}
{{- if $isRemoteBase -}}
{{- $cssPath := cond (ne $plyrCssAsset "") $plyrCssAsset "plyr.css" -}}
{{- $plyrCssUrl := printf "%s/%s" $plyrBase $cssPath -}}
{{- with try (resources.GetRemote $plyrCssUrl) -}}
{{- with .Err -}}
{{- errorf "Could not retrieve Plyr css file from %s. Reason: %s." $plyrCssUrl . -}}
{{- else with .Value -}}
{{- with resources.Copy "css/plyr.css" . -}}
{{- $plyrCss := . | fingerprint -}}
<link rel="stylesheet" href="{{ $plyrCss.RelPermalink }}" integrity="{{ $plyrCss.Data.Integrity }}" crossorigin="anonymous" />
{{- end -}}
{{- end -}}
{{- end -}}
{{- else if $plyrCssAsset -}}
{{- with resources.Get $plyrCssAsset -}}
{{- $plyrCss := . | fingerprint -}}
<link rel="stylesheet" href="{{ $plyrCss.RelPermalink }}" integrity="{{ $plyrCss.Data.Integrity }}" crossorigin="anonymous" />
{{- else -}}
{{- errorf "Plyr css asset not found at %q" $plyrCssAsset -}}
{{- end -}}
{{- end -}}
{{- /* JS retrieval */ -}}
{{- if $isRemoteBase -}}
{{- $jsPath := cond (ne $plyrJsAsset "") $plyrJsAsset (printf "plyr.polyfilled%s.js" $minSuffix) -}}
{{- $plyrJsUrl := printf "%s/%s" $plyrBase $jsPath -}}
{{- with try (resources.GetRemote $plyrJsUrl) -}}
{{- with .Err -}}
{{- errorf "Could not retrieve Plyr js file from %s. Reason: %s." $plyrJsUrl . -}}
{{- else with .Value -}}
{{- with resources.Copy (printf "js/plyr.polyfilled%s.js" $minSuffix) . -}}
{{- $plyrJs := . | fingerprint -}}
<script defer src="{{ $plyrJs.RelPermalink }}" integrity="{{ $plyrJs.Data.Integrity }}" crossorigin="anonymous"></script>
{{- end -}}
{{- end -}}
{{- end -}}
{{- else if $plyrJsAsset -}}
{{- with resources.Get $plyrJsAsset -}}
{{- $plyrJs := . | fingerprint -}}
<script defer src="{{ $plyrJs.RelPermalink }}" integrity="{{ $plyrJs.Data.Integrity }}" crossorigin="anonymous"></script>
{{- else -}}
{{- errorf "Plyr js asset not found at %q" $plyrJsAsset -}}
{{- end -}}
{{- end -}}
<script>
document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll(".content video, .content audio, .content [data-plyr-provider]").forEach((el) => {
new Plyr(el);
});
});
</script>