{{- $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 = $cache.MediaType -}} {{- $cache = (strings.TrimPrefix "public/" $cache) -}} {{- end -}} {{- end -}} {{- $data = strings.TrimPrefix "/" $url | relURL -}} {{- if $cache -}} {{- $data = $cache | relURL -}} {{- end -}} {{- if $remote -}} {{- $data = $url -}} {{- end -}} {{- if (in $data "pdf") -}} {{- $type = "application/pdf" -}} {{- end -}}

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