{{- $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.