From face7b570c5f51fb5f972540a5fc205ebfbca207 Mon Sep 17 00:00:00 2001 From: tdro Date: Sat, 25 Jun 2022 21:44:41 -0400 Subject: themes/default/layouts/shortcodes/video: Try to not fetch again on cache bust Use immutable link and check if already fetched. --- .../default/layouts/partials/video-container.html | 28 ++++++++++++++-------- themes/default/layouts/shortcodes/imgur-video.html | 9 +++---- themes/default/layouts/shortcodes/video.html | 3 ++- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/themes/default/layouts/partials/video-container.html b/themes/default/layouts/partials/video-container.html index 44bbf6b..2d782e6 100644 --- a/themes/default/layouts/partials/video-container.html +++ b/themes/default/layouts/partials/video-container.html @@ -2,19 +2,27 @@ {{- $caption := .Caption -}} {{- $public := print "public/" .Source -}} {{- $timestamp := print "#t=" .Start "," .End -}} +{{- $immutable := print (.RelURL | humanize | urlize) "-" (.Source | sha256 | truncate 8 "") -}} +{{- $extension := path.Ext .Source -}} +{{- $fileCache := print $.Author "/media/" $immutable $extension -}} -{{- with $remote := resources.GetRemote .Source -}} - {{- with .Err -}} - {{- if fileExists $public -}} +{{- if not (fileExists (path.Join "public/" $fileCache)) -}} + {{- with $remote := resources.GetRemote .Source -}} + {{- with .Err -}} + {{- if fileExists $public -}} + {{- else -}} + {{- $caption = "No local video data found for source" -}} + {{- end -}} {{- else -}} - {{ $caption = "No local video data found for source" }} - {{- end -}} + {{- end }} + {{- $cache = . | resources.Copy $fileCache -}} + {{- $cache = $cache.RelPermalink -}} {{- else -}} - {{ end }} - {{- $cache = .Content | resources.FromString (print $.Author "/media/" (. | urlize)) -}} - {{- $cache = $cache.RelPermalink }} -{{ else }} - {{ $caption = "No remote video data found for source" }} + {{- $caption = "No remote video data found for source" -}} + {{- end -}} +{{- else -}} + {{- $cache = resources.Get (path.Join "public/" $fileCache) -}} + {{- $cache = $cache.RelPermalink -}} {{- end -}} diff --git a/themes/default/layouts/shortcodes/imgur-video.html b/themes/default/layouts/shortcodes/imgur-video.html index a4ed76c..c60cbff 100644 --- a/themes/default/layouts/shortcodes/imgur-video.html +++ b/themes/default/layouts/shortcodes/imgur-video.html @@ -8,9 +8,10 @@ {{- partial "video-container.html" (dict - "Author" .Page.Section - "Caption" $caption - "Options" $options - "Source" (print "https://i.imgur.com/" $id ".mp4") + "Author" .Page.Section + "Caption" $caption + "Options" $options + "RelURL" .Page.RelPermalink + "Source" (print "https://i.imgur.com/" $id ".mp4") ) -}} diff --git a/themes/default/layouts/shortcodes/video.html b/themes/default/layouts/shortcodes/video.html index 9148853..3820db0 100644 --- a/themes/default/layouts/shortcodes/video.html +++ b/themes/default/layouts/shortcodes/video.html @@ -17,11 +17,12 @@ (dict "Author" .Page.Section "Caption" $caption - "Options" $options "End" $end "Height" $height + "Options" $options "Poster" $poster "Preload" $preload + "RelURL" .Page.RelPermalink "Source" $source "Source" $source "Start" $start -- cgit v1.2.3