aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.json9
-rw-r--r--config.toml6
-rw-r--r--config.yaml11
-rw-r--r--content/canory/messages/pdf.md5
-rw-r--r--themes/default/layouts/shortcodes/attach.html57
-rw-r--r--themes/default/layouts/shortcodes/pdf.html13
6 files changed, 70 insertions, 31 deletions
diff --git a/config.json b/config.json
index 3e85479..a2ce6f0 100644
--- a/config.json
+++ b/config.json
@@ -122,13 +122,11 @@
"'self'",
"www.youtube-nocookie.com",
"en.m.wikipedia.org",
- "odysee.com",
- "www.gutenberg.org"
+ "odysee.com"
],
"img-src": [
"'self'",
- "http://preview.test",
- "www.gutenberg.org"
+ "http://preview.test"
],
"manifest-src": [
"'self'"
@@ -137,8 +135,7 @@
"'self'"
],
"object-src": [
- "'self'",
- "www.gutenberg.org"
+ "'self'"
],
"prefetch-src": [
"'self'"
diff --git a/config.toml b/config.toml
index 1ba7ca2..9d65688 100644
--- a/config.toml
+++ b/config.toml
@@ -97,11 +97,11 @@ enableRobotsTXT = true
default-src = ["'self'"]
font-src = ["'self'"]
form-action = ["'self'", "lite.duckduckgo.com"]
- frame-src = ["'self'", "www.youtube-nocookie.com", "en.m.wikipedia.org", "odysee.com", "www.gutenberg.org"]
- img-src = ["'self'", "http://preview.test", "www.gutenberg.org"]
+ frame-src = ["'self'", "www.youtube-nocookie.com", "en.m.wikipedia.org", "odysee.com"]
+ img-src = ["'self'", "http://preview.test"]
manifest-src = ["'self'"]
media-src = ["'self'"]
- object-src = ["'self'", "www.gutenberg.org"]
+ object-src = ["'self'"]
prefetch-src = ["'self'"]
script-src-elem = ["'self'"]
script-src = ["'self'"]
diff --git a/config.yaml b/config.yaml
index 58a8d37..bc00a9d 100644
--- a/config.yaml
+++ b/config.yaml
@@ -87,12 +87,11 @@ params:
default-src: ["'self'"]
font-src: ["'self'"]
form-action: ["'self'", lite.duckduckgo.com]
- frame-src: ["'self'", www.youtube-nocookie.com, en.m.wikipedia.org, odysee.com,
- www.gutenberg.org]
- img-src: ["'self'", http://preview.test, www.gutenberg.org]
+ frame-src: ["'self'", www.youtube-nocookie.com, en.m.wikipedia.org, odysee.com]
+ img-src: ["'self'", http://preview.test]
manifest-src: ["'self'"]
media-src: ["'self'"]
- object-src: ["'self'", www.gutenberg.org]
+ object-src: ["'self'"]
prefetch-src: ["'self'"]
script-src-elem: ["'self'"]
script-src: ["'self'"]
@@ -297,9 +296,9 @@ markup:
anchorLineNos: true
codeFences: true
guessSyntax: true
- hl_Lines: ""
+ hl_Lines: ''
hl_inline: false
- lineAnchors: ""
+ lineAnchors: ''
lineNoStart: 1
lineNos: false
lineNumbersInTable: false
diff --git a/content/canory/messages/pdf.md b/content/canory/messages/pdf.md
index 74ff0be..c1d118d 100644
--- a/content/canory/messages/pdf.md
+++ b/content/canory/messages/pdf.md
@@ -1,12 +1,11 @@
+++
date = "2022-03-07T02:20:51+00:00"
lastmod = "2022-03-07T02:20:51+00:00"
-tags = [ "docs", "pdf" ]
+tags = [ "docs", "attach" ]
author = "canory"
+++
Heard you like {{< abbr `PDFs` "Portable Document Format" >}} but hate accidently
downloading them. Charles Dickens is a word wizard.
-{{< pdf >}}
-
+{{< attach >}}
diff --git a/themes/default/layouts/shortcodes/attach.html b/themes/default/layouts/shortcodes/attach.html
new file mode 100644
index 0000000..c122d75
--- /dev/null
+++ b/themes/default/layouts/shortcodes/attach.html
@@ -0,0 +1,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 }} &middot; {{ end }}
+ {{ print "[Source](" $url ")" | markdownify }}
+ </footer>
+</document-attachment>
diff --git a/themes/default/layouts/shortcodes/pdf.html b/themes/default/layouts/shortcodes/pdf.html
deleted file mode 100644
index 6c627b5..0000000
--- a/themes/default/layouts/shortcodes/pdf.html
+++ /dev/null
@@ -1,13 +0,0 @@
-{{- $url := default "https://www.gutenberg.org/files/98/old/2city12p.pdf" (.Get "url" | default (.Get 0)) -}}
-{{- $title := default "PDF Document" (.Get "title" | default (.Get 1)) -}}
-{{- $caption := default (print $title " ([Download](" $url "))") (.Get "caption" | default (.Get 2)) -}}
-
-<portable-document title="{{ $title }}">
- <object type="application/pdf" data="{{ $url }}">
- <p>
- Your browser does not support a <code>PDF</code> (Portable Document Format)
- plugin. Here's a <a href="{{ $url }}">link to the PDF file</a> instead.
- </p>
- </object>
- <footer>{{ $caption | markdownify }}</footer>
-</portable-document>