diff options
Diffstat (limited to 'themes/default/layouts/shortcodes/attach.html')
-rw-r--r-- | themes/default/layouts/shortcodes/attach.html | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/themes/default/layouts/shortcodes/attach.html b/themes/default/layouts/shortcodes/attach.html new file mode 100644 index 0000000..55b5744 --- /dev/null +++ b/themes/default/layouts/shortcodes/attach.html @@ -0,0 +1,58 @@ +{{- $url := default "/canory/media/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 := "" -}} +{{- $author := .Page.Section -}} +{{- $extension := path.Ext $url -}} +{{- $immutable := print $url | anchorize -}} +{{- $localFile := path.Join "public/" $url -}} +{{- $type := "application/octet-stream" -}} +{{- $storage := print $author "/media/" $immutable $extension -}} +{{- $cached := fileExists (path.Join "public/" $storage) -}} + +{{- if not $cached -}} + {{- with $remote := cond (default true $.Page.Site.Params.site.offline) false (resources.GetRemote $url) -}} + {{- with .Err -}} + {{- if not (fileExists $localFile) -}} + {{- $caption = "No local attachment data found for source" -}} + {{- warnf "Attachment local fetch error: %s" $url -}} + {{- end -}} + {{- else -}} + {{- $type = $remote.MediaType -}} + {{- $cache = $remote | resources.Copy $storage -}} + {{- $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/" $storage) -}} + {{- $type = .MediaType -}} + {{- $cache = print ("" | absURL) (strings.TrimLeft "public" $cache) -}} + {{- end -}} +{{- end -}} + +{{- $data := or $cache $url -}} + +{{- 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 rel="canonical" 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> |