blob: c122d759dc6f0f0e82cb414aeac0a43454078ef0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
{{- $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 -}}
<document-attachment title="{{ $title }}">
<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.
</p>
</object>
<footer>
{{ $caption | markdownify }}
<br />
Index: {{ with $cache }} {{ print "[Cache](" $cache ")" | markdownify }} · {{ end }}
{{ print "[Source](" $url ")" | markdownify }}
</footer>
</document-attachment>
|