aboutsummaryrefslogtreecommitdiff
path: root/themes
diff options
context:
space:
mode:
authortdro <tdro@noreply.example.com>2023-02-10 00:28:45 -0500
committertdro <tdro@noreply.example.com>2023-02-10 00:28:45 -0500
commit8500c3134099aba462368d2ad21db8b22de2254e (patch)
treec495967d72e54261db860bef918ccc23e17e3872 /themes
parent017bc1c9317ab352981202dc7da0e3f9dc314043 (diff)
downloadcanory-8500c3134099aba462368d2ad21db8b22de2254e.tar.gz
canory-8500c3134099aba462368d2ad21db8b22de2254e.tar.bz2
canory-8500c3134099aba462368d2ad21db8b22de2254e.zip
themes/default/layouts/shortcodes/pdf.html -> attach.html
Generalize into attach shortcode
Diffstat (limited to 'themes')
-rw-r--r--themes/default/layouts/shortcodes/attach.html57
-rw-r--r--themes/default/layouts/shortcodes/pdf.html13
2 files changed, 57 insertions, 13 deletions
diff --git a/themes/default/layouts/shortcodes/attach.html b/themes/default/layouts/shortcodes/attach.html
new file mode 100644
index 0000000..c122d75
--- /dev/null
+++ b/themes/default/layouts/shortcodes/attach.html
@@ -0,0 +1,57 @@
+{{- $url := default "https://www.gutenberg.org/files/98/old/2city12p.pdf" (.Get "url" | default (.Get 0)) -}}
+{{- $title := default "Attachment" (.Get "title" | default (.Get 1)) -}}
+{{- $caption := default $title (.Get "caption" | default (.Get 2)) -}}
+{{- $remote := default "" (.Get "remote" | default (.Get 3)) -}}
+
+{{- $data := "" -}}
+{{- $cache := "" -}}
+{{- $type := "application/octet-stream" -}}
+{{- $author := .Page.Section -}}
+{{- $immutable := print $url | anchorize -}}
+{{- $extension := path.Ext $url -}}
+{{- $fileCache := print $author "/media/" $immutable $extension -}}
+{{- $notCached := not (fileExists (path.Join "public/" $fileCache)) -}}
+
+{{- if $notCached -}}
+ {{- with $remote := resources.GetRemote $url -}}
+ {{- with .Err -}}
+ {{- warnf "Attachment fetch %s" . -}}
+ {{- if not (fileExists $fileCache) -}}
+ {{- $caption = "No local attachment data found for source" -}}
+ {{- end -}}
+ {{- else -}}
+ {{- $type = .MediaType -}}
+ {{- $cache = . | resources.Copy $fileCache -}}
+ {{- $cache = $cache.Permalink -}}
+ {{- end -}}
+ {{- else -}}
+ {{- $caption = "No remote attachment data found for source" -}}
+ {{- end -}}
+{{- else -}}
+ {{- with $cache = resources.Get (path.Join "public/" $fileCache) -}}
+ {{- $type = .MediaType -}}
+ {{- $cache = $cache.Content | resources.FromString $fileCache -}}
+ {{- $cache = $cache.Permalink -}}
+ {{- end -}}
+{{- end -}}
+
+{{- $data := $cache -}}
+
+{{- if $remote -}}
+ {{- $data = $url -}}
+{{- end -}}
+
+<document-attachment title="{{ $title }}">
+ <object type="{{ $type }}" data="{{ $data }}">
+ <p>
+ Your browser does not support the <code>{{ $type }}</code> plugin. Here's a
+ <a href="{{ $data }}">link to the file</a> instead.
+ </p>
+ </object>
+ <footer>
+ {{ $caption | markdownify }}
+ <br />
+ Index: {{ with $cache }} {{ print "[Cache](" $cache ")" | markdownify }} &middot; {{ end }}
+ {{ print "[Source](" $url ")" | markdownify }}
+ </footer>
+</document-attachment>
diff --git a/themes/default/layouts/shortcodes/pdf.html b/themes/default/layouts/shortcodes/pdf.html
deleted file mode 100644
index 6c627b5..0000000
--- a/themes/default/layouts/shortcodes/pdf.html
+++ /dev/null
@@ -1,13 +0,0 @@
-{{- $url := default "https://www.gutenberg.org/files/98/old/2city12p.pdf" (.Get "url" | default (.Get 0)) -}}
-{{- $title := default "PDF Document" (.Get "title" | default (.Get 1)) -}}
-{{- $caption := default (print $title " ([Download](" $url "))") (.Get "caption" | default (.Get 2)) -}}
-
-<portable-document title="{{ $title }}">
- <object type="application/pdf" data="{{ $url }}">
- <p>
- Your browser does not support a <code>PDF</code> (Portable Document Format)
- plugin. Here's a <a href="{{ $url }}">link to the PDF file</a> instead.
- </p>
- </object>
- <footer>{{ $caption | markdownify }}</footer>
-</portable-document>