diff options
Diffstat (limited to 'themes/default/layouts/shortcodes/attach.html')
-rw-r--r-- | themes/default/layouts/shortcodes/attach.html | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/themes/default/layouts/shortcodes/attach.html b/themes/default/layouts/shortcodes/attach.html index f453da5..55b5744 100644 --- a/themes/default/layouts/shortcodes/attach.html +++ b/themes/default/layouts/shortcodes/attach.html @@ -1,37 +1,38 @@ -{{- $url := default "https://www.gutenberg.org/files/98/old/2city12p.pdf" (.Get "url" | default (.Get 0)) -}} +{{- $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 := "" -}} -{{- $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)) -}} +{{- $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 $notCached -}} +{{- if not $cached -}} {{- with $remote := cond (default true $.Page.Site.Params.site.offline) false (resources.GetRemote $url) -}} {{- with .Err -}} - {{- warnf "Attachment fetch %s" . -}} - {{- if not (fileExists $fileCache) -}} + {{- if not (fileExists $localFile) -}} {{- $caption = "No local attachment data found for source" -}} + {{- warnf "Attachment local fetch error: %s" $url -}} {{- end -}} {{- else -}} - {{- $type = .MediaType -}} - {{- $cache = . | resources.Copy $fileCache -}} + {{- $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/" $fileCache) -}} + {{- with $cache = resources.Get (path.Join "public/" $storage) -}} {{- $type = .MediaType -}} - {{- $cache = $cache.Content | resources.FromString $fileCache -}} - {{- $cache = $cache.Permalink -}} + {{- $cache = print ("" | absURL) (strings.TrimLeft "public" $cache) -}} {{- end -}} {{- end -}} @@ -45,7 +46,7 @@ <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. + <a rel="canonical" href="{{ $data }}">link to the file</a> instead. </p> </object> <footer> |