From 8500c3134099aba462368d2ad21db8b22de2254e Mon Sep 17 00:00:00 2001 From: tdro Date: Fri, 10 Feb 2023 00:28:45 -0500 Subject: themes/default/layouts/shortcodes/pdf.html -> attach.html Generalize into attach shortcode --- themes/default/layouts/shortcodes/attach.html | 57 +++++++++++++++++++++++++++ themes/default/layouts/shortcodes/pdf.html | 13 ------ 2 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 themes/default/layouts/shortcodes/attach.html delete mode 100644 themes/default/layouts/shortcodes/pdf.html (limited to 'themes') 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 -}} + + + +

+ Your browser does not support the {{ $type }} plugin. Here's a + link to the file instead. +

+
+
+ {{ $caption | markdownify }} +
+ Index: {{ with $cache }} {{ print "[Cache](" $cache ")" | markdownify }} · {{ end }} + {{ print "[Source](" $url ")" | markdownify }} +
+
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)) -}} - - - -

- Your browser does not support a PDF (Portable Document Format) - plugin. Here's a link to the PDF file instead. -

-
- -
-- cgit v1.2.3