diff options
Diffstat (limited to 'themes')
-rw-r--r-- | themes/default/layouts/shortcodes/attach.html | 57 | ||||
-rw-r--r-- | themes/default/layouts/shortcodes/pdf.html | 13 |
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 }} · {{ 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> |