{{- $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 := "" -}} {{- $canonical := "" -}} {{- $author := .Page.Section -}} {{- $extension := path.Ext $url -}} {{- $immutable := print $url | anchorize -}} {{- $public := path.Join "public/" $url -}} {{- $type := "application/octet-stream" -}} {{- $storage := print $author "/media/" $immutable $extension -}} {{- $cached := fileExists (path.Join "public/" $storage) -}} {{- $target := urls.Parse $url -}} {{- $self := urls.Parse .Page.Site.BaseURL -}} {{- $prurl := eq (findRE `^/\w` $url | len) 0 -}} {{- $local := or (eq $target.Host $self.Host) (and (strings.HasPrefix $url "/") (not $prurl)) -}} {{- if not $cached -}} {{- $fetch := false -}} {{- if and (isset site.Params.site "offline") (eq $.Page.Site.Params.site.offline false) -}} {{- $fetch = resources.GetRemote $url -}} {{- end -}} {{- with $fetch -}} {{- with .Err -}} {{- if not $local -}} {{- $caption = "Unable to load remote source data" -}} {{- warnf "Attachment remote fetch error: %s" $url -}} {{- end -}} {{- else -}} {{- $type = $fetch.MediaType -}} {{- $cache = $fetch | resources.Copy $storage -}} {{- $cache = $cache.Permalink -}} {{- end -}} {{- else -}} {{- if not $local -}} {{- $caption = "Offline unable to load remote source data" -}} {{- warnf "Offline attachment remote fetch error: %s" $url -}} {{- end -}} {{- end -}} {{- else -}} {{- with $cache = resources.Get (path.Join "public/" $storage) -}} {{- $type = $cache.MediaType -}} {{- $cache = $cache | strings.TrimPrefix "public/" | strings.TrimPrefix "/public/" -}} {{- end -}} {{- end -}} {{- if and $local (not (fileExists $public)) -}} {{- $caption = "No local attachment data found for source" -}} {{- warnf "Attachment local fetch error: %s" $url -}} {{- end -}} {{- if $local -}} {{- $data = strings.TrimPrefix "/" $url | relURL -}} {{- $canonical = $data -}} {{- end -}} {{- if not $local -}} {{- $canonical = $url -}} {{- end -}} {{- if $cache -}} {{- $data = $cache | relURL -}} {{- end -}} {{- if $remote -}} {{- $data = $url -}} {{- end -}} {{- if (in $data "pdf") -}} {{- $type = "application/pdf" -}} {{- end -}} {{- $cache = partial "function-normalize-url.html" $cache -}} {{- $canonical = partial "function-normalize-url.html" $canonical -}} {{- $data = partial "function-normalize-url.html" $data -}} {{- $url = partial "function-normalize-url.html" $url -}}

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