{{- $cache := "" -}} {{- $source := "" -}} {{- $timestamp := "" -}} {{- $caption := .Caption -}} {{- $remote := .Remote -}} {{- $public := print "public/" .Source -}} {{- $immutable := print (.RelURL | humanize | urlize) "-" (.Source | sha256 | truncate 8 "") -}} {{- $extension := path.Ext .Source -}} {{- $storage := print $.Author "/media/" $immutable $extension -}} {{- $cached := fileExists (path.Join "public/" $storage) -}} {{- 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 not $cached -}} {{- with $remote := cond (default true $.Context.Site.Params.site.offline) false (resources.GetRemote .Source) -}} {{- with .Err -}} {{- warnf "Video fetch %s" . -}} {{- if not (fileExists $public) -}} {{- $caption = "No local video data found for source" -}} {{- end -}} {{- else -}} {{- $cache = $remote | resources.Copy $storage -}} {{- $cache = $cache.Permalink -}} {{- end -}} {{- else -}} {{- $caption = "Unable to load remote source data" -}} {{- end -}} {{- else -}} {{- with $cache = resources.Get (path.Join "public/" $storage) -}} {{- $cache = print ("" | absURL) (strings.TrimLeft "public" $cache) -}} {{- end -}} {{- end -}} {{- $source = $cache -}} {{- if .Remote -}} {{- $source = .Source -}} {{- end -}}