aboutsummaryrefslogtreecommitdiff
path: root/themes/default/layouts/shortcodes
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2023-09-27 19:20:15 -0400
committertdro <tdro@noreply.example.com>2023-09-27 19:29:23 -0400
commit6069820a482201d390b8a9a1f1828a47ae724037 (patch)
tree48900947e36ece663dbb1dfa764e12a8884f888b /themes/default/layouts/shortcodes
parent9f80796917bfc7df5f170019efe4b61c83a09559 (diff)
downloadcanory-6069820a482201d390b8a9a1f1828a47ae724037.tar.gz
canory-6069820a482201d390b8a9a1f1828a47ae724037.tar.bz2
canory-6069820a482201d390b8a9a1f1828a47ae724037.zip
themes/default/layouts/shortcodes/attach: Clear up logic a bit
Avoid writing file again after being saved
Diffstat (limited to 'themes/default/layouts/shortcodes')
-rw-r--r--themes/default/layouts/shortcodes/attach.html21
1 files changed, 11 insertions, 10 deletions
diff --git a/themes/default/layouts/shortcodes/attach.html b/themes/default/layouts/shortcodes/attach.html
index baddb92..dfd472f 100644
--- a/themes/default/layouts/shortcodes/attach.html
+++ b/themes/default/layouts/shortcodes/attach.html
@@ -5,33 +5,34 @@
{{- $data := "" -}}
{{- $cache := "" -}}
-{{- $type := "application/octet-stream" -}}
{{- $author := .Page.Section -}}
-{{- $immutable := print $url | anchorize -}}
{{- $extension := path.Ext $url -}}
+{{- $immutable := print $url | anchorize -}}
+{{- $localFile := path.Join "public/" $url -}}
+{{- $type := "application/octet-stream" -}}
{{- $fileCache := print $author "/media/" $immutable $extension -}}
-{{- $notCached := not (fileExists (path.Join "public/" $fileCache)) -}}
+{{- $cached := fileExists (path.Join "public/" $fileCache) -}}
-{{- if $notCached -}}
+{{- if not $cached -}}
{{- with $remote := cond (default true $.Page.Site.Params.site.offline) false (resources.GetRemote $url) -}}
{{- with .Err -}}
- {{- warnf "Attachment fetch %s" . -}}
- {{- if not (fileExists $fileCache) -}}
+ {{- if not (fileExists $localFile) -}}
{{- $caption = "No local attachment data found for source" -}}
+ {{- warnf "Attachment local fetch error: %s" $url -}}
{{- end -}}
{{- else -}}
- {{- $type = .MediaType -}}
- {{- $cache = . | resources.Copy $fileCache -}}
+ {{- $type = $remote.MediaType -}}
+ {{- $cache = $remote | resources.Copy $fileCache -}}
{{- $cache = $cache.Permalink -}}
{{- end -}}
{{- else -}}
{{- $caption = "Unable to load remote source data" -}}
+ {{- warnf "Attachment remote fetch error: %s" $url -}}
{{- end -}}
{{- else -}}
{{- with $cache = resources.Get (path.Join "public/" $fileCache) -}}
{{- $type = .MediaType -}}
- {{- $cache = $cache.Content | resources.FromString $fileCache -}}
- {{- $cache = $cache.Permalink -}}
+ {{- $cache = print ("" | absURL) (strings.TrimLeft "public" $cache) -}}
{{- end -}}
{{- end -}}