aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2022-06-25 21:44:41 -0400
committertdro <tdro@noreply.example.com>2022-06-25 21:44:41 -0400
commitface7b570c5f51fb5f972540a5fc205ebfbca207 (patch)
treebabe2bde81a9df934c10e8757dbdc9e3a0c7a2c8
parent6746a1fdc8c5f7571b6061ba3ecf68acb25730d5 (diff)
downloadcanory-face7b570c5f51fb5f972540a5fc205ebfbca207.tar.gz
canory-face7b570c5f51fb5f972540a5fc205ebfbca207.tar.bz2
canory-face7b570c5f51fb5f972540a5fc205ebfbca207.zip
themes/default/layouts/shortcodes/video: Try to not fetch again on cache bust
Use immutable link and check if already fetched.
-rw-r--r--themes/default/layouts/partials/video-container.html28
-rw-r--r--themes/default/layouts/shortcodes/imgur-video.html9
-rw-r--r--themes/default/layouts/shortcodes/video.html3
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 -}}
<video-container>
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