aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/partials/video-container.html
blob: 7d934e642bb7014aebdbdfb3c91756014040d344 (plain)
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
{{- $cache      := "" -}}
{{- $source     := "" -}}
{{- $timestamp  := "" -}}
{{- $caption    := .Caption -}}
{{- $remote     := .Remote -}}
{{- $public     := print "public/" .Source -}}
{{- $immutable  := print (.RelURL | humanize | urlize) "-" (.Source | sha256 | truncate 8 "") -}}
{{- $extension  := path.Ext .Source -}}
{{- $fileCache  := print $.Author "/media/" $immutable $extension -}}
{{- $notCached  := not (fileExists (path.Join "public/" $fileCache)) -}}

{{- if .Start -}}
  {{- $timestamp = print "#t=" .Start -}}
{{- end -}}

{{- if .End -}}
  {{- $timestamp = print "#t=," .End -}}
{{- end -}}

{{- if and .Start .End -}}
  {{- $timestamp = print "#t=" .Start "," .End -}}
{{- end -}}

{{- if $notCached -}}
  {{- with $remote := resources.GetRemote .Source -}}
    {{- with .Err -}}
      {{- warnf "Video fetch %s" . -}}
      {{- if not (fileExists $public) -}}
        {{- $caption = "No local video data found for source" -}}
      {{- end -}}
    {{- else -}}
      {{- $cache = . | resources.Copy $fileCache -}}
      {{- $cache = $cache.Permalink -}}
    {{- end -}}
  {{- else -}}
    {{- $caption = "No remote video data found for source" -}}
  {{- end -}}
{{- else -}}
  {{- with $cache = resources.Get (path.Join "public/" $fileCache) -}}
    {{- $cache = $cache.Content | resources.FromString $fileCache -}}
    {{- $cache = $cache.Permalink -}}
  {{- end -}}
{{- end -}}

{{- $source = $cache -}}

{{- if .Remote -}}
  {{- $source = .Source -}}
{{- end -}}

<video-container>
  <video
    title="{{ .Title }}"
    preload="{{ .Preload }}"
    data-orientation="{{ .Orientation }}"
    {{ with .Poster }} poster="{{ . }}" {{ end -}}
    {{ with .Width }} width="{{ . }}" {{ end -}}
    {{ with .Height }} height="{{ . }}" {{ end -}}
    {{- range $value := (split .Options " ") }}
    {{- printf `%s=""` $value | safeHTMLAttr }}
    {{ end -}}
  >
    <source src="{{ $source }}{{ $timestamp }}" />
    {{ print "Video: " $caption "." | markdownify }}
    <p>
      Sorry, your browser does not support embedded videos. Here is a
      <a href="{{ .Source }}">link to the video</a> instead.
    </p>
  </video>
  <footer>
    {{ $caption | markdownify }}
    <br />
    Index: {{ with $cache }} {{ print "[Cache](" . ")" | markdownify }} &middot; {{ end }}
    {{ print "[Source](" .Source ")" | markdownify }}
  </footer>
</video-container>