From 8a77cf95f080b06bf95f51e365d955844f08c075 Mon Sep 17 00:00:00 2001 From: tdro Date: Thu, 2 Nov 2023 11:11:08 -0400 Subject: themes/default/layouts/partials/video-container: Avoid extraneous resource copying Carefully refer directly to resource --- themes/default/layouts/partials/video-container.html | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'themes/default/layouts/partials') diff --git a/themes/default/layouts/partials/video-container.html b/themes/default/layouts/partials/video-container.html index af1a50d..9e28e3d 100644 --- a/themes/default/layouts/partials/video-container.html +++ b/themes/default/layouts/partials/video-container.html @@ -6,8 +6,8 @@ {{- $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)) -}} +{{- $storage := print $.Author "/media/" $immutable $extension -}} +{{- $cached := fileExists (path.Join "public/" $storage) -}} {{- if .Start -}} {{- $timestamp = print "#t=" .Start -}} @@ -21,7 +21,7 @@ {{- $timestamp = print "#t=" .Start "," .End -}} {{- end -}} -{{- if $notCached -}} +{{- if not $cached -}} {{- with $remote := cond (default true $.Context.Site.Params.site.offline) false (resources.GetRemote .Source) -}} {{- with .Err -}} {{- warnf "Video fetch %s" . -}} @@ -29,16 +29,15 @@ {{- $caption = "No local video data found for source" -}} {{- end -}} {{- else -}} - {{- $cache = . | resources.Copy $fileCache -}} + {{- $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/" $fileCache) -}} - {{- $cache = $cache.Content | resources.FromString $fileCache -}} - {{- $cache = $cache.Permalink -}} + {{- with $cache = resources.Get (path.Join "public/" $storage) -}} + {{- $cache = print ("" | absURL) (strings.TrimLeft "public" $cache) -}} {{- end -}} {{- end -}} -- cgit v1.2.3